
Beyond APIs: Build a Serverless Database App with AWS DynamoDB
Turn a basic serverless API into a real application with persistent cloud storage. Learn how to integrate Amazon DynamoDB, AWS Lambda, and API Gateway to build a Python-powered CRUD application with hands-on examples.
Beyond APIs: Build a Serverless Database Application with AWS DynamoDB
AWS Student Builder Group – JJCET | Week 04
Your API can receive requests. Your Lambda function can process them. But where does the data actually live? Let's connect the missing piece.

1. Introduction: An API is only the beginning
Imagine building a student management application.
A student registers through your website. The application receives their details, processes the request, and displays a success message.
But there is one important question:
Where is that student's information stored?
If your backend only returns a JSON response without saving anything, the information disappears after the request finishes.
Real-world applications need databases to store, retrieve, update, and delete information.
Traditionally, developers use databases such as MySQL, PostgreSQL, and MongoDB. In AWS, we can also use fully managed database services that reduce infrastructure management.
Today, we are exploring Amazon DynamoDB, a fully managed NoSQL database service designed for applications that need fast, scalable data access.
In our previous article, we built StudentHub using Amazon API Gateway and AWS Lambda.
Now, we are upgrading it.
Our new architecture will connect three AWS services:
- Amazon API Gateway – Receives HTTP requests.
- AWS Lambda – Processes application logic.
- Amazon DynamoDB – Permanently stores student information.
By the end, we will build a basic serverless CRUD application that can create, read, update, and delete student records.
2. What is Amazon DynamoDB?
Amazon DynamoDB is a fully managed NoSQL database service provided by AWS.
Unlike traditional relational databases, DynamoDB stores information in tables containing items and attributes.
Let's understand this through an example.
Imagine a college database containing student information.
Student ID | Name | Department | Year |
|---|---|---|---|
101 | Arun | IT | 3 |
102 | Kumar | CSE | 2 |
103 | Priya | AI&DS | 3 |
In DynamoDB:
- A table stores a collection of related items.
- An item represents an individual record.
- An attribute represents a property of that record.
- A primary key uniquely identifies an item.
For example:
{ "id": "101", "name": "Arun", "department": "IT", "year": 3}This JSON-like structure represents a DynamoDB item.
Why use DynamoDB?
- Fully managed database infrastructure.
- Automatic scaling capabilities.
- Flexible data models.
- Fast key-based access.
- Integration with AWS Lambda.
- Support for event-driven applications.
DynamoDB vs traditional relational databases
Feature | DynamoDB | MySQL |
|---|---|---|
Database type | NoSQL | Relational |
Data structure | Items and attributes | Tables and rows |
Schema | Flexible | Structured schema |
Query model | Key-based access and indexes | SQL queries |
Infrastructure | Fully managed | Depends on deployment |
Best suited for | Key-value and document workloads | Relational data and joins |
Neither database is universally better. The right choice depends on your application requirements and data relationships.
3. Understanding our project architecture
Let's connect what we learned in the previous articles.
Project: StudentHub 2.0
Our objective is to build a serverless student management API that stores student records permanently.
The architecture looks like this:
STUDENT / CLIENT | | HTTP Request | v AMAZON API GATEWAY | | AWS LAMBDA (Python Backend) | | IAM EXECUTION ROLE | v AMAZON DYNAMODB (Student Table) | | JSON RESPONSE | v API CLIENTWhat happens when a request arrives?
- A student sends a request from a browser or application.
- API Gateway receives the HTTP request.
- API Gateway invokes the Lambda function.
- Lambda processes the request.
- Lambda communicates with DynamoDB using the AWS SDK.
- DynamoDB performs the requested database operation.
- Lambda returns the result.
- API Gateway sends the response to the client.
The important concept is that each service has a specific responsibility.
API Gateway handles incoming requests, Lambda handles application logic, and DynamoDB manages persistent data.
4. What are CRUD operations?
Before building the application, let's understand four important database operations.
CRUD stands for:
Operation | HTTP Method | Purpose |
|---|---|---|
Create | POST | Add a new student |
Read | GET | Retrieve student details |
Update | PUT | Modify student information |
Delete | DELETE | Remove a student record |
These operations are fundamental to most application backends.
For example, consider a college management system.
- Registering a student uses CREATE.
- Viewing student information uses READ.
- Updating a department uses UPDATE.
- Removing an outdated record uses DELETE.
Now let's implement these operations using AWS.
5. Hands-on project: Build StudentHub 2.0

Prerequisites
Before starting, make sure you have:
- An AWS account.
- Access to AWS Management Console.
- Basic Python knowledge.
- Basic understanding of HTTP methods.
- An API testing tool such as Postman.
Cost reminder: AWS services may incur charges. Review the current pricing for DynamoDB, Lambda, and API Gateway. Configure a budget alert, use suitable learning settings, and delete resources when the exercise is complete.
Step 1 – Create a DynamoDB table
First, we need a place to store student records.
- Open AWS Management Console.
- Search for Amazon DynamoDB.
- Select Tables.
- Choose Create table.
- Enter the table name:
StudentRecords- Under Partition key, enter:
id- Select String as the key type.
- Keep the default settings for this learning exercise.
- Select Create table.
Wait until the table becomes active.
Congratulations! Your first DynamoDB table is ready.
Step 2 – Create a Lambda function
Now we need backend logic to communicate with DynamoDB.
- Open AWS Lambda.
- Select Create function.
- Choose Author from scratch.
- Enter:
StudentHubDatabaseAPI- Select a currently supported Python runtime.
- Create a basic execution role with CloudWatch logging permissions.
- Select Create function.
Step 3 – Give Lambda permission to access DynamoDB
This is an important security step.
Lambda cannot automatically access every AWS service.
We must grant it permission using an IAM execution role.
Open your Lambda function:
- Select Configuration.
- Open Permissions.
- Select the execution role.
- Add a policy that permits the required DynamoDB actions on your
StudentRecordstable.
For this tutorial, the required actions are:
dynamodb:PutItemdynamodb:GetItemdynamodb:Scandynamodb:UpdateItemdynamodb:DeleteItemRestrict the policy's Resource to the ARN of your specific DynamoDB table.
Avoid giving the function unrestricted administrator access.
Step 4 – Add Python code to Lambda
Now let's implement our CRUD operations.
Open the Lambda code editor and use the following example:
import jsonimport osimport uuidimport boto3
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table( os.environ["TABLE_NAME"])
def lambda_handler(event, context):
method = event["requestContext"]["http"]["method"]
path = event.get("pathParameters") or {} student_id = path.get("id")
try:
# CREATE if method == "POST":
student = json.loads(event.get("body") or "{}")
if not student.get("name") or not student.get("department"): return response(400, { "message": "Name and department are required" })
student["id"] = str(uuid.uuid4())
table.put_item(Item=student)
return response(201, { "message": "Student created successfully", "student": student })
# READ ALL elif method == "GET" and not student_id:
result = table.scan()
return response(200, { "students": result.get("Items", []) })
# READ ONE elif method == "GET":
result = table.get_item( Key={"id": student_id} )
student = result.get("Item")
if not student: return response(404, { "message": "Student not found" })
return response(200, student)
# UPDATE elif method == "PUT":
body = json.loads(event.get("body") or "{}")
if not body.get("name") or not body.get("department"): return response(400, { "message": "Name and department are required" })
result = table.update_item( Key={"id": student_id}, UpdateExpression="SET #n = :n, department = :d", ConditionExpression="attribute_exists(id)", ExpressionAttributeNames={ "#n": "name" }, ExpressionAttributeValues={ ":n": body["name"], ":d": body["department"] }, ReturnValues="ALL_NEW" )
return response(200, { "message": "Student updated", "student": result["Attributes"] })
# DELETE elif method == "DELETE":
table.delete_item( Key={"id": student_id}, ConditionExpression="attribute_exists(id)" )
return response(200, { "message": "Student deleted successfully" })
return response(405, { "message": "Method not allowed" })
except dynamodb.meta.client.exceptions.ConditionalCheckFailedException: return response(404, { "message": "Student not found" })
except Exception: print("Database operation failed") return response(500, { "message": "Internal server error" })
def response(status, data):
return { "statusCode": status, "headers": { "Content-Type": "application/json" }, "body": json.dumps(data, default=str) }Select Deploy.
What does this code do?
- POST creates a new student.
- GET retrieves all students.
- GET with an ID retrieves one student.
- PUT updates an existing student.
- DELETE removes a student.
The code uses Boto3, the AWS SDK for Python, to communicate with DynamoDB.
For this learning project, GET-all uses Scan for simplicity. In production, prefer Query with suitable keys or indexes for efficient access to larger datasets.
Step 5 – Configure the Lambda environment variable
Our code reads the table name from an environment variable.
To configure it:
- Open Lambda.
- Select Configuration.
- Choose Environment variables.
- Select Edit.
- Add:
Key: TABLE_NAME
Value: StudentRecords- Save the configuration.
This avoids hardcoding the database table name throughout the code.
Step 6 – Create an API using API Gateway
Now we need to expose our backend through HTTP endpoints.
- Open Amazon API Gateway.
- Select Create API.
- Choose HTTP API.
- Select Build.
- Add your Lambda function as the integration.
- Enter the API name:
StudentHub-Database-APICreate the following routes:
Method | Route | Operation |
|---|---|---|
POST | /students | Create |
GET | /students | Read all |
GET | /students/{id} | Read one |
PUT | /students/{id} | Update |
DELETE | /students/{id} | Delete |
Connect each route to the Lambda integration.
Configure the API Gateway permission to invoke your Lambda function. The console can help establish this integration permission.
Deploy the API to a stage and copy the invoke URL.
Your serverless database API is now ready for testing.
6. Test the application using Postman
Let's verify that the complete application works.
Assume your API URL is:
https://your-api-id.execute-api.region.amazonaws.comTest 1 – Create a student
Method:
POSTEndpoint:
/studentsRequest body:
{ "name": "Arun", "department": "IT", "year": 3}Expected response:
{ "message": "Student created successfully", "student": { "id": "generated-student-id", "name": "Arun", "department": "IT", "year": 3 }}The application generates a unique ID and stores the record in DynamoDB.
Test 2 – Retrieve all students
Method:
GETEndpoint:
/studentsExpected response:
{ "students": [ { "id": "generated-student-id", "name": "Arun", "department": "IT", "year": 3 } ]}Test 3 – Retrieve one student
Method:
GETEndpoint:
/students/generated-student-idThe API should return the matching student record.
Test 4 – Update student information
Method:
PUTEndpoint:
/students/generated-student-idRequest body:
{ "name": "Arun Kumar", "department": "CSE"}The API updates the existing record.
Test 5 – Delete a student
Method:
DELETEEndpoint:
/students/generated-student-idThe student record is removed from the table.
You have now implemented all four CRUD operations using AWS.
7. What did we build?
Let's review our complete architecture.
AWS service | Responsibility |
|---|---|
API Gateway | Receives HTTP requests |
Lambda | Executes backend logic |
DynamoDB | Stores student information |
IAM | Controls permissions |
CloudWatch | Monitors execution and logs |
The application is now capable of receiving requests, processing them, storing information, and returning responses.
Most importantly, we have built a backend without maintaining a traditional application server.
8. Security and best practices
A functional database application must also be secure.
Keep these practices in mind:
1. Apply least-privilege IAM permissions
Give Lambda only the DynamoDB actions and resource access it requires.
2. Validate incoming data
Check required fields, data types, lengths, and allowed values before storing information.
3. Protect your API
Consider authentication using Amazon Cognito or JWT authorizers.
4. Avoid exposing sensitive information
Do not return internal database errors, credentials, or private information to clients.
5. Monitor your application
Use CloudWatch logs and metrics to identify errors and investigate unexpected behavior.
6. Design for production
Consider pagination, Query operations, conditional writes, idempotency, backup policies, and appropriate capacity settings.
9. Challenge of the Week
Now it's time to extend StudentHub 2.0.
Beginner challenge
- Add a course attribute to each student.
- Store multiple student records.
- Test all CRUD operations.
Intermediate challenge
- Add input validation.
- Return proper error messages.
- Implement a student search feature using an appropriate key or index.
- Add authentication.
Advanced challenge
- Connect a React frontend to the API.
- Build a complete student management dashboard.
- Add Amazon Cognito authentication.
- Explore DynamoDB Streams.
- Trigger Lambda when database records change.
Your mission: Build your own serverless CRUD application using API Gateway, Lambda, and DynamoDB. Share your architecture, screenshots, and lessons learned with the student community.
10. What should you explore next?
After learning DynamoDB, explore:
AWS service | Learning objective |
|---|---|
Amazon Cognito | User authentication |
DynamoDB Streams | Database change events |
Amazon SQS | Message queues |
Amazon SNS | Notifications |
AWS Step Functions | Workflow automation |
AWS CloudFormation | Infrastructure as code |
AWS SAM | Serverless application deployment |
Amazon CloudWatch | Monitoring and observability |
These services will help you move from simple serverless applications towards more complete cloud architectures.
Conclusion: From writing APIs to building real applications
In our previous article, we learned how to create a serverless API using API Gateway and Lambda.
Today, we added the missing component: persistent cloud storage.
By connecting DynamoDB to our Lambda backend, we transformed a simple API into an application that can create, retrieve, update, and delete real records.
This is an important step in understanding how modern cloud applications are designed.
Remember:
An API receives the request. Lambda processes the logic. DynamoDB stores the data.
When these services work together, you can build powerful applications without managing traditional database and application servers.
At the AWS Student Builder Group – JJCET, we believe that the best way to learn cloud technology is to build, experiment, troubleshoot, and share knowledge.
Don't just learn AWS services individually. Learn how to connect them to solve real problems.
Keep learning. Keep building. Keep growing.
Official AWS learning resources
Author: AWS Student Builder Group – JJCET
Series: AWS Learning Journey | Week 04
Topics: Amazon DynamoDB · AWS Lambda · Amazon API Gateway · Python · Boto3 · NoSQL · CRUD · Serverless Architecture
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article