How to get Dynamo DB access from VPC lambda function?

0

If I add a DynamoDB Endpoint Gateway (my preference as less costly), I dont get any options to get a DNS URL to use as an Endpoint. If I add a DynamoDB Endpoint Interface, I cant connect using any of the DNS URL's listed - even if I use a security profile with all access TCP in and out. I beleive my Role has all the necassery privilages. I'm also quite curious why a DNS URL would be an Endpoint URL anways..

So how do I get an working DynamoDB endpoint?

3 Answers
0

When you add a VPC Gateway Endpoint for DynamoDB, the table routing is automatically added for you. Your normal DynamoDB Client with the standard endpoint will always choose the Gateway Endpoint to route traffic, unlike Interface Gateway, where you must explicitly set the endpoint.

More information on the configuration can be found here: create-gateway-endpoint-ddb

profile pictureAWS
EXPERT
answered 14 days ago
  • (From my VPC lambda function) I can now access MySQL with the relevant subnets, and DynamoDB with the other subnets. I wish to access both DB's but providing the MySQL subnets breaks DynamoDB (and maybe vice versa). How can I acccess both DB systems?

0

Many thanks for the above help. What I didnt realise (and still dont understand why) is that having unnecassery subnets configured stops the gateway working. After detaching the unneccassery subnets from my function, I now have DynamoDB working.

answered 13 days ago
-1

To enable DynamoDB access from a Lambda function within a VPC, you should use a DynamoDB Gateway Endpoint, which is the correct and preferred approach. Here's how to set it up and use it:

  1. Create a Gateway Endpoint for DynamoDB in your VPC. This doesn't provide a specific DNS URL because it works at the routing level.

  2. Ensure that the route table associated with your Lambda function's subnets has a route for the DynamoDB service prefix list (pl-xxxxxxxx) pointing to the gateway endpoint (vpce-xxxxxxxx).

  3. Configure your Lambda function to use the VPC and the appropriate subnets.

  4. Make sure your Lambda function's IAM role has the necessary permissions to access DynamoDB.

  5. In your Lambda function code, you don't need to specify a special endpoint URL. Use the standard DynamoDB endpoint for your region (e.g., dynamodb.us-west-2.amazonaws.com).

The reason you don't get a specific DNS URL with a Gateway Endpoint is that it operates at the network routing level, not at the DNS level. When your Lambda function makes a request to DynamoDB, the VPC's routing table directs the traffic through the Gateway Endpoint, keeping it within the AWS network.

Regarding your confusion about DNS URLs as endpoints: For Interface Endpoints (which you mentioned trying), AWS provides DNS names because these endpoints create elastic network interfaces with private IP addresses in your VPC. However, for DynamoDB, a Gateway Endpoint is the recommended and more cost-effective solution.

If you're still having trouble connecting, double-check the following:

  1. Verify that the Gateway Endpoint is correctly associated with your VPC and route table.
  2. Ensure your Lambda function is configured to use the VPC and the correct subnets.
  3. Check that your Lambda function's IAM role has the necessary permissions for DynamoDB access.
  4. Make sure your VPC has DNS hostnames and DNS resolution enabled.

By following these steps, your Lambda function should be able to access DynamoDB through the Gateway Endpoint without needing to specify a special endpoint URL in your code.
Sources
Connect to DynamoDB from a Lambda instance in a VPC | AWS re:Post
Securing DynamoDB connections using VPC endpoints and IAM policies" - Amazon DynamoDB
Lambda Function not connecting to DynamoDB via VPC | AWS re:Post
verify gateway endpoint functionality | AWS re:Post

profile picture
answered 16 days ago
profile pictureAWS
EXPERT
reviewed 16 days ago
  • Many thanks for your detailed answer though if you could please break down step 2 into very simple instructions as routes/subnets/CIDR blocks is the area I really struggle with.

    [ Ensure that the route table associated with your Lambda function's subnets has a route for the DynamoDB service prefix list (pl-######) pointing to the gateway endpoint (vpce-######). ]

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions