This a brief guide to connecting a Lambda function to Elasticache using C#, but the language isn’t really important here. It’s the connections you make.
As with everything, these two things are actually pretty easy to connect if you get everything right and understand what’s going on.
Normally with Lambda functions:
- they run in their own Virtual Private Cloud (VPC) context
- they connect to the internet via that contextual VPC’s Internet Gateway (IGW)
- they cannot access private subnets in other VPCs
Elasticache does not (typically) allow access to its nodes from outside its own VPC. The solution is to run Lambda functions inside your own VPC.
So to create a new VPC and a use Lambda functions that connect to Elasticache, you have these steps:
- Create a Virtual Private Cloud (VPC)
- Add an Internet Gateway (IGW) to the VPC
- Update the route table
- Add private subnets
- Add public subnets
- Add Elasticache to the private subnets
- Update or Create the Lambda function role
- Add Lambda functions to the public subnets
- Test your functions