AWS Lambda and Elasticache

Dan Blackwell
1 min readJul 17, 2020


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:

  1. Create a Virtual Private Cloud (VPC)
  2. Add an Internet Gateway (IGW) to the VPC
  3. Update the route table
  4. Add private subnets
  5. Add public subnets
  6. Add Elasticache to the private subnets
  7. Update or Create the Lambda function role
  8. Add Lambda functions to the public subnets
  9. Test your functions