Listen to this Post
AWS API Gateway offers direct integrations with DynamoDB, eliminating the need for Lambda functions in certain scenarios. However, this requires using Velocity Template Language (VTL) to build mapping templates for data transformation. While this reduces the number of components, it introduces complexity in maintaining VTL scripts.
You Should Know:
1. Setting Up API Gateway with DynamoDB
To integrate API Gateway directly with DynamoDB, follow these steps:
1. Create a DynamoDB Table
aws dynamodb create-table \ --table-name MyTable \ --attribute-definitions AttributeName=id,AttributeType=S \ --key-schema AttributeName=id,KeyType=HASH \ --billing-mode PAY_PER_REQUEST
2. Create an API Gateway REST API
aws apigateway create-rest-api --name DynamoDBProxy
3. Define Resources and Methods
aws apigateway create-resource --rest-api-id YOUR_API_ID --parent-id ROOT_ID --path-part items aws apigateway put-method --rest-api-id YOUR_API_ID --resource-id RESOURCE_ID --http-method GET --authorization-type NONE
4. Configure Integration Request with VTL
Example VTL template for a `GET` request:
{
"TableName": "MyTable",
"KeyConditionExpression": "id = :v1",
"ExpressionAttributeValues": {
":v1": {"S": "$input.params('id')"}
}
}
5. Deploy the API
aws apigateway create-deployment --rest-api-id YOUR_API_ID --stage-name prod
2. Testing the Integration
Use `curl` to test the API:
curl -X GET https://YOUR_API_ID.execute-api.REGION.amazonaws.com/prod/items?id=123
3. Handling Updates (PUT/POST)
For updates, configure a `PUT` method with a VTL template:
{
"TableName": "MyTable",
"Item": {
"id": {"S": "$input.path('$.id')"},
"data": {"S": "$input.path('$.data')"}
}
}
4. Monitoring & Debugging
Enable CloudWatch Logs for API Gateway:
aws apigateway update-stage --rest-api-id YOUR_API_ID --stage-name prod \ --patch-operations op=replace,path=/accessLogSettings/destinationArn,value=arn:aws:logs:REGION:ACCOUNT_ID:log-group:API-Gateway-Logs
What Undercode Say
Direct API Gateway-DynamoDB integration reduces Lambda overhead but introduces VTL complexity. Use this approach for simple CRUD operations but avoid it for complex transformations. For advanced use cases, Lambda remains a better choice.
Expected Output:
A fully functional API Gateway endpoint that reads/writes to DynamoDB without Lambda, using VTL templates for request/response mapping.
Reference:
Deploy AWS API Gateway to read and update DynamoDB without Lambda
References:
Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅



