Skip to content

09 Lambda Dynamodb

DodaTech 1 min read

title: Lambda and DynamoDB Integration for Serverless APIs weight: 19 date: 2026-06-28 lastmod: 2026-06-28 description: Integrate AWS Lambda with DynamoDB for serverless API data storage including CRUD operations, querying with filters, DynamoDB Streams triggers, and capacity management. tags: [api-development, serverless]


Lambda integrates with DynamoDB for serverless data storage using the boto3 SDK with CRUD operations, DynamoDB Streams for change-data-capture triggers, and single-table design for efficient querying.

```python
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
import os

dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table(os.environ["TABLE_NAME"])

def lambda_handler(event, context):
    http_method = event["httpMethod"]

    if http_method == "GET":
        user_id = event["pathParameters"]["user_id"]
        response = table.get_item(Key={"userId": user_id})
        item = response.get("Item")
        if not item:
            return {"statusCode": 404, "body": json.dumps({"error": "Not found"})}
        return {"statusCode": 200, "body": json.dumps(item)}

    elif http_method == "POST":
        body = json.loads(event["body"])
        table.put_item(Item=body)
        return {"statusCode": 201, "body": json.dumps(body)}

    elif http_method == "DELETE":
        user_id = event["pathParameters"]["user_id"]
        table.delete_item(Key={"userId": user_id})
        return {"statusCode": 204}

What's Next

Now learn about Lambda S3 integration in Building Serverless APIs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro