
Building a Serverless API with AWS Lambda, Amazon API Gateway, and Amazon DynamoDB (step‑by‑step for students)
A step‑by‑step tutorial showing students how to build a serverless “to‑do list” API on AWS using Lambda, API Gateway, and DynamoDB, from creating the database table to testing HTTP endpoints with real requests. It’s designed as an accessible first cloud project that can be published on AWS Builder Center and reused in portfolios or extended with authentication, monitoring, and a frontend.
As a student, it’s easy to spend hours watching cloud tutorials without ever deploying something you can actually show in a portfolio. In this article, I’ll walk you through building a simple serverless API using AWS Lambda, Amazon API Gateway, and Amazon DynamoDB, ideal as a first real project to showcase in internships or entry‑level job applications.
By the end, you’ll have a working “to‑do list” API that you can connect to a web or mobile frontend and demo live.
What we’re going to build
We’ll create a small REST API with three main operations:
-
POST /tasks– create a new task.
-
GET /tasks– list all tasks.
-
DELETE /tasks/{id}– delete a specific task.
Task data will be stored in an Amazon DynamoDB table, while the application logic runs inside a single AWS Lambda function exposed via Amazon API Gateway HTTP API.
This architecture is fully serverless: you don’t provision or manage servers, and AWS automatically handles scaling, patching, and availability.
Prerequisites
Before you start, make sure you have:
- An active AWS account (student accounts via AWS Builder Center work fine).
- Basic programming knowledge (Python or Node.js; this article uses Python).
- Access to the AWS Management Console with permissions to create Lambda functions, DynamoDB tables, and API Gateway APIs.
If you’re new to these services, it helps to skim the “Getting Started” sections for DynamoDB and API Gateway first, then come back to this tutorial.
Solution architecture
Our solution uses three core AWS services:
- Amazon DynamoDB: a fully managed NoSQL key‑value database optimized for high scale and low latency.
- AWS Lambda: a serverless compute service that runs your code in response to events or API calls, and charges only for the compute time you use.
- Amazon API Gateway HTTP API: a managed service for creating and managing APIs that route requests to Lambda or other HTTP backends.
The request flow is:
- A client (for example, a React web app or a curl command) sends an HTTP request to your API Gateway endpoint.
- API Gateway invokes the Lambda function corresponding to the route and HTTP method.
- The Lambda function reads from or writes to the DynamoDB table and returns a JSON response, which API Gateway sends back to the client.
Step 1: Create the DynamoDB table
- In the AWS Management Console, search for DynamoDB and open it.
- Choose Create table.
- Configure:
- Table name:
Tasks
- Partition key:
id(typeString)
- Keep default settings for capacity (on‑demand capacity is fine for student projects and fits within the free tier for small workloads).
- Choose Create table and wait until the table is active.
We’ll store each task as an item with at least:
-
id: unique identifier for the task.
-
title: short title or description.
-
done: boolean flag (true/false) indicating completion.
Step 2: Create the AWS Lambda function
- In the console, search for Lambda and open it.
- Choose Create function.
- Select:
- Author from scratch.
- Function name:
TasksApiFunction.
- Runtime:
Python 3.11(or the latest supported Python runtime).
- Leave the other options as defaults and choose Create function.
Example Python code
In the Lambda console’s code editor, replace the default code with:
import jsonimport uuidimport boto3
dynamodb = boto3.resource("dynamodb")table = dynamodb.Table("Tasks")
def lambda_handler(event, context): http_method = event.get("httpMethod") path = event.get("path")
if http_method == "POST" and path == "/tasks": body = json.loads(event.get("body") or "{}") title = body.get("title", "Untitled task")
task_id = str(uuid.uuid4()) item = { "id": task_id, "title": title, "done": False, } table.put_item(Item=item)
return _response(201, {"message": "Task created", "task": item})
if http_method == "GET" and path == "/tasks": result = table.scan() tasks = result.get("Items", []) return _response(200, {"tasks": tasks})
if http_method == "DELETE" and path.startswith("/tasks/"): task_id = path.split("/")[-1] table.delete_item(Key={"id": task_id}) return _response(200, {"message": "Task deleted", "id": task_id})
return _response(400, {"error": "Unsupported route"})
def _response(status_code, body): return { "statusCode": status_code, "headers": {"Content-Type": "application/json"}, "body": json.dumps(body), }Choose Deploy to save the updated function.
This implementation is intentionally simple: it supports basic create, list, and delete operations and returns JSON responses suitable for most frontends.
Step 3: Expose the Lambda function via Amazon API Gateway
- Open Amazon API Gateway in the console.
- Choose Create API and then Build under HTTP API (HTTP APIs are cheaper and simpler than full REST APIs for this kind of project).
- Configure:
- Integration: choose Add integration → Lambda → select
TasksApiFunction.
- API name:
TasksApi.
- Create routes:
-
POST /tasks→ integration:TasksApiFunction.
-
GET /tasks→ integration:TasksApiFunction.
-
DELETE /tasks/{id}→ integration:TasksApiFunction.
Make sure the HTTP method and path are passed correctly to the Lambda, so the function can distinguish between create, list, and delete operations.
After deployment, note the invoke URL of your API (it looks like
https://xxxxxx.execute-api.<region>.amazonaws.com ).
Step 4: Test the API
You can test your API using curl, a browser, or tools like Postman or Insomnia.
Create a task (POST)
curl -X POST \ https://YOUR_ENDPOINT/tasks \ -H "Content-Type: application/json" \ -d '{"title": "Study AWS today"}'You should receive a
201 response with a JSON body containing message and task (including an id , title , and done field).List tasks (GET)
curl -X GET https://YOUR_ENDPOINT/tasksThe response should include a
tasks array with all items retrieved from the DynamoDB table.Delete a task (DELETE)
curl -X DELETE https://YOUR_ENDPOINT/tasks/TASK_IDReplace
TASK_ID with the id value from the task you created earlier.
If everything is configured correctly, the item will be removed from the Tasks table and the API will return a confirmation message.
Possible improvements
Once the basic API works, you can extend the project with:
- Authentication and authorization using Amazon Cognito or JWT tokens, so only authenticated users can manage tasks.
- Logging and monitoring through Amazon CloudWatch Logs and Lambda metrics, giving you visibility into errors and performance.
- A simple frontend built with React, Vue, or plain HTML+JavaScript that consumes this API and displays tasks.
- Infrastructure as code using AWS SAM or AWS CDK, so you can reproduce the environment in other accounts or regions using templates instead of manual clicks.
Each of these improvements can become a separate follow‑up article on Builder Center, allowing you to build a series that shows a clear learning trajectory.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article