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