Connect to AWS ElastiCache with In-Transit Encryption + Auth from client other than redis-cli+stunnel
For both clients the default TLS behavior is to verify the server certificate, which we needed to disable. The solution for both clients is as follows:
NodeJS client:
const redis = require('redis')
const client = redis.createClient({host: hostOrIp, port: 6379, auth_pass: 'thePassword', tls: { checkServerIdentity: () => undefined }})
Ruby client:
require "redis"
redis = Redis.new(url: connectionString, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
I ran into a similar problem, but instead of ECONNRESET I was getting a timeout. 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.
- Because encryption in-transit was turned on, I needed to pass
redis.RedisClient(... ssl=True)
. The redis-py page mentions thatssl_cert_reqs
needs to be set toNone
for use with ElastiCache similar to what was answered, but that didn't seem to be true in my case. I think AWS has updated the ElastiCache certs to have the proper hostname. 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.