I am trying to make Serverless work with Elasticache. I wrote a custom CloudFormation file based on serverless-examples/serverless-infrastructure repo. I managed to put Elasticache and Lambda in one subnet (checked with the cli). I retrieve the host and the port from the Outputs, but whenever I am trying to connect with node-redis the connection times out. Here are the relevant parts:
11
votes
Being in one subnet doesn't automatically allow connections. You didn't mention security group settings.
- Michael - sqlbot
The default inbound tcp port for Redis is 6379: docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/…
- Dave Maple
What does your code do besides connecting to ec? Does it use dynamodb, s3 or other aws resources? If it does that might be what's timing out, because you don't have NAT
- Tolbahady
2 Answers
6
votes
I ran into this issue as well, but with Python. For me, there were a few problems that had to be ironed out
- The lambda needs VPC permissions.
- The ElastiCache security group needs an inbound rule from the Lambda security group that allows communication on the Redis port. I thought they could just be in the same security group.
- And the real kicker: I had turned on encryption in-transit. This meant that I needed to pass
redis.RedisClient(... ssl=True). The redis-py page mentions thatssl_cert_reqsneeds to be set toNonefor use with ElastiCache, but that didn't seem to be true in my case. I did however need to passssl=True.
It makes sense that ssl=True needed to be set but the connection was just timing out so I went round and round trying to figure out what the problem with the permissions/VPC/SG setup was.