AWS Builder Center: Learn, Build and Connect with builders in the AWS community
AWS Builder Center is the official home for builders on AWS. Share and read what others are working on, follow people who inspire you, explore training and workshops, and find tools to support what you're building.
How do I connect to DynamoDB from a Lambda instance in a VPC?
3 minute read
3
I want to integrate Amazon DynamoDB with my AWS Lambda instance in an Amazon Virtual Private Cloud (Amazon VPC).
For Basic information, configure the following:
For Function name, enter a name for your function.
For Runtime, choose a runtime option. In this example, Python 3.12 is used.
For Architecture, choose x86_64.
Under Advanced settings, configure the following:
Select Enable VPC, and then select your VPC.
For Subnets, select only private subnets.
For Security groups, select the default security group.
Choose Create function.
On the Function details page, under Code source, enter the following code:
Test your function. Note: To test the function, the AWS Identity and Access Management (IAM) role for Lambda must have the appropriate permissions. For more information, see Managing permissions in AWS Lambda.
Additional troubleshooting
To troubleshoot a Lambda function that's attached to a VPC, take the following actions:
Remove any connections to public subnets from your Lambda function. If you connect to public subnets, then traffic tries to pass through the public subnets and can cause intermittent timeout issues.
Update your private subnets that are associated with your Lambda function to route through your DynamoDB VPC gateway endpoint. These endpoints have AWS managed prefix lists that simplify the configuration of security group settings between Lambda and DynamoDB.
Example private subnet route table:
Route Table: rtb-12345
Destination Gateway Status
10.0.0.0/16 local active
pl-1234 vpce-1234 active