1. Introduction

Serverless computing allows developers to build and deploy applications without managing traditional servers. AWS provides several services that work together to create scalable, cost-effective and highly available applications.

In this hands-on project, I built an AWS Serverless GET & POST API using Amazon S3, Amazon API Gateway, AWS Lambda and Amazon DynamoDB.

The application allows users to submit data through a web interface, store records in DynamoDB using a POST request, and retrieve stored records using a GET request.

The main objective was to understand how AWS serverless services integrate to build a complete API-based application.

2. Project Architecture

The application follows a serverless architecture in which the frontend, API layer, compute layer and database work together.

Architecture Flow

 USER / WEB BROWSER | v AMAZON S3 (Static Website) | | API Requests v API GATEWAY /users | +------+------+ | | v v GET Request POST Request | | v v AWS Lambda AWS Lambda GetStudentData PostStudentData | | +------+------+ | v AMAZON DYNAMODB StudentData 

Request workflow:

  • Amazon S3 hosts the frontend website.
  • The browser sends GET and POST requests directly to API Gateway.
  • API Gateway routes requests to the appropriate Lambda function.
  • Lambda functions read or write records in DynamoDB.
  • API Gateway returns the response to the browser.

3. AWS Services and Their Responsibilities

AWS Service| Purpose
Amazon S3| Hosts the static website
Amazon API Gateway| Creates and manages GET and POST API endpoints
AWS Lambda| Executes backend Python code
Amazon DynamoDB| Stores and retrieves application records
AWS IAM| Controls permissions between AWS services

4. DynamoDB Database Configuration

The first step was creating a DynamoDB table to store application records.

Table configuration:

  • Table Name: "StudentData"
  • Partition Key: "Studentid"
  • Key Type: String

The application stores the following attributes:

  • Studentid
  • name
  • phone_number
  • city
  • state
  • country
  • email

The partition key uniquely identifies each record.

5. Creating the AWS Lambda Functions

Two separate Lambda functions were created to handle different HTTP methods.

5.1 GET Lambda Function

Function Name: "GetStudentData"

Runtime: Python 3.12

The GET function retrieves records from DynamoDB.

It supports two operations:

  1. Retrieve all available records.
  2. Retrieve a specific record using its Student ID.

Example endpoint:

GET /users
GET /users?id=101

Python implementation:

import json
import boto3
import os

dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("StudentData")

def lambda_handler(event, context):
try:
params = event.get("queryStringParameters") or {}
student_id = params.get("id")

 if student_id: response = table.get_item( Key={"Studentid": str(student_id)} ) data = response.get("Item") if not data: return { "statusCode": 404, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps({ "message": "Student not found" }) } result = data else: response = table.scan() items = response.get("Items", []) while "LastEvaluatedKey" in response: response = table.scan( ExclusiveStartKey=response["LastEvaluatedKey"] ) items.extend(response.get("Items", [])) result = items return { "statusCode": 200, "headers": { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json" }, "body": json.dumps(result, default=str) } except Exception as e: return { "statusCode": 500, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps({"error": str(e)}) } 

How it works:

  • Reads the query parameter from the API request.
  • Uses "get_item()" when a Student ID is provided.
  • Uses "scan()" to retrieve all records when no ID is provided.
  • Returns the result in JSON format.
  • Returns HTTP status 200 when successful.

5.2 POST Lambda Function

Function Name: "PostStudentData"

Runtime: Python 3.12

The POST function receives JSON data and saves a new record in DynamoDB.

Example request body:

{
"Studentid": "101",
"name": "Ali",
"phone_number": "03001234567",
"city": "Sahiwal",
"state": "Punjab",
"country": "Pakistan",
"email": "ali@example.com"
}

Python implementation:

import json
import boto3

dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("StudentData")

def lambda_handler(event, context):
try:
body = event.get("body")

 if isinstance(body, str): body = json.loads(body) elif body is None: body = {} required_fields = [ "Studentid", "name", "phone_number", "city", "state", "country", "email" ] for field in required_fields: if not body.get(field): return { "statusCode": 400, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps({ "error": f"{field} is required" }) } item = { field: str(body[field]) for field in required_fields } table.put_item( Item=item, ConditionExpression="attribute_not_exists(Studentid)" ) return { "statusCode": 201, "headers": { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json" }, "body": json.dumps({ "message": "Record created successfully", "data": item }) } except Exception as e: if "ConditionalCheckFailedException" in str(e): return { "statusCode": 409, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps({ "error": "Student ID already exists" }) } return { "statusCode": 500, "headers": { "Access-Control-Allow-Origin": "*" }, "body": json.dumps({"error": str(e)}) } 

How it works:

  • Receives JSON data from API Gateway.
  • Validates the required fields.
  • Creates a DynamoDB item.
  • Prevents an existing Student ID from being overwritten.
  • Returns HTTP status 201 after successful creation.

6. IAM Permissions Configuration

Lambda requires permission to access the DynamoDB table.

An IAM execution role was assigned to the Lambda functions.

Required DynamoDB permissions include:

GET function:

  • dynamodb:GetItem
  • dynamodb:Scan

POST function:

  • dynamodb:PutItem

The permissions should be restricted to the required DynamoDB table instead of granting unnecessary access.

7. API Gateway Configuration

Amazon API Gateway was used to expose the Lambda functions through HTTP endpoints.

API Configuration:

  • API Type: REST API
  • API Name: "StudentManagementAPI"
  • Resource: "/users"
  • Methods: GET and POST
  • Integration: AWS Lambda Proxy Integration
  • Deployment Stage: "prod"

GET Method

The GET method was integrated with:

"GetStudentData"

POST Method

The POST method was integrated with:

"PostStudentData"

CORS was configured to allow frontend requests, including GET, POST and OPTIONS.

After configuring the methods and integrations, the API was deployed to the "prod" stage.

API Endpoint:

https://API-ID.execute-api.REGION.amazonaws.com/prod/users

8. Frontend Development and S3 Hosting

A frontend website was developed using:

  • HTML
  • CSS
  • JavaScript

The website provides the following functionality:

  1. Enter a Student ID and other record details.
  2. Submit data using the POST API.
  3. Retrieve all records using the GET API.
  4. Search for a specific record using Student ID.

The frontend JavaScript connects to the API Gateway endpoint.

const API_URL =
"https://API-ID.execute-api.REGION.amazonaws.com/prod/users";

The website files were uploaded to an Amazon S3 bucket, and Static Website Hosting was enabled.

The API endpoint was configured in the frontend code to connect the website with the backend services.

9. API Testing and Results

Both API methods were tested to verify that the application was working correctly.

POST API Testing

Request:

POST /users

A JSON record was submitted through the frontend/API request.

Expected successful response:

{
"message": "Record created successfully"
}

Actual project test result:

  • HTTP Status Code: "201"
  • Result: Record created successfully.

GET API Testing

Request:

GET /users

The API retrieved records stored in the DynamoDB table.

Actual project test result:

  • HTTP Status Code: "200"
  • Result: Data retrieved successfully.

Testing Summary

Test| HTTP Status| Result
POST API| 201| Successful
GET API| 200| Successful
Website Hosting| —| Successful

10. Challenges and Solutions

During implementation, several configuration and integration steps required attention.

  1. Lambda and DynamoDB permissions
  • Challenge: Lambda requires permission to access DynamoDB.
  • Solution: Configured the appropriate IAM execution role and database permissions.
  1. API and frontend integration
  • Challenge: The frontend must communicate with the correct API endpoint.
  • Solution: Configured the deployed API URL in JavaScript.
  1. CORS configuration
  • Challenge: Browser-based API requests require correct cross-origin configuration.
  • Solution: Configured CORS for the required API methods and response headers.
  1. API deployment
  • Challenge: Changes to API configuration must be deployed before they become available through the stage.
  • Solution: Deployed the API to the "prod" stage after configuration changes.

11. Key Learnings

Through this project, I gained practical experience with:

  • Building a serverless application on AWS.
  • Creating and configuring DynamoDB tables.
  • Developing Python-based AWS Lambda functions.
  • Implementing GET and POST API methods.
  • Integrating API Gateway with Lambda.
  • Configuring IAM permissions.
  • Hosting static websites using Amazon S3.
  • Connecting frontend applications with backend APIs.
  • Testing HTTP responses and troubleshooting integration issues.

12. Security and Production Considerations

This project demonstrates the basic serverless workflow. Before using it in production:

  • Add authentication and authorization.
  • Apply least-privilege IAM policies.
  • Validate and sanitize incoming data.
  • Restrict CORS to trusted website origins.
  • Avoid exposing personal or sensitive records through a public website.
  • Consider using Amazon CloudFront and HTTPS for production website delivery.
  • Enable appropriate logging and monitoring.

13. Conclusion

The AWS Serverless GET & POST API Project demonstrates how multiple AWS services can work together to build a functional serverless application.

Amazon S3 provides frontend hosting, API Gateway manages API requests, AWS Lambda handles backend processing, and Amazon DynamoDB stores application data.

The successful GET and POST tests confirmed that the frontend, API and database were integrated correctly.

This project provided valuable hands-on experience in serverless application development and strengthened my understanding of AWS cloud architecture.

Technologies Used: Amazon S3 | Amazon API Gateway | AWS Lambda | Amazon DynamoDB | AWS IAM | Python 3.12 | HTML | CSS | JavaScript

Tags: "#AWS" "#Serverless" "#AmazonLambda" "#APIGateway" "#DynamoDB" "#CloudComputing"