How to connect elasticache and dynamoDb from aws-lambda without using NAT Gateway
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Connecting to ElastiCache
For ElastiCache, the approach involves setting up the cluster inside the same VPC, allowing direct access from the Lambda without needing internet or a NAT Gateway.
Steps to Connect
- Create an ElastiCache Cluster:
- Ensure that the ElastiCache cluster is launched in the same VPC and associated subnets as the Lambda function.
- Configure Subnet Groups:
- Use subnet groups that are aligned with the availability zones your Lambda function uses.
- Security Groups:
- Set up security group rules to allow access between the Lambda function and ElastiCache Cluster. Typically, this involves allowing inbound/outbound traffic on port 6379 for Redis.
- Update Lambda Function:
- Make sure the Lambda function and ElastiCache nodes share the same VPC, subnets, and security groups to enable communication without routing through the internet.
Summary Table
| AWS Service | Connection Method | Required Setup | Key Benefits |
| DynamoDB | VPC Endpoint | VPC Endpoint creation, IAM policies | Secure access without NAT Gateway and costs |
| ElastiCache | VPC Connection | VPC settings, security group rules | Direct, low-latency access inside the VPC |
Conclusion
By understanding the networking needs of Lambda functions and leveraging AWS's networking features like VPC Endpoints, you can efficiently connect your serverless applications to services like DynamoDB and ElastiCache without the additional cost and complexity of a NAT Gateway. This approach not only simplifies architecture but also enhances security by limiting exposure to the internet.
Always ensure proper security considerations are taken into account when configuring VPC setups and IAM policies to secure your AWS environment.
Related reading
- How to connect to outside world from amazon vpc?
- How to convert a boto3 Dynamo DB item to a regular dictionary in Python?
- How to convert AWS EC2 instance type t2 to instance type t4g?
- How to copy multiple file from local to s3?
- How to copy or duplicate an AWS Lambda function
- how to copy s3 object from one bucket to another using python boto3
- How to copy/move all objects in Amazon S3 from one prefix to other using the AWS SDK for Node.js
- How to create a domain and a subdomain in AWS?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.