ioredis: Unhandled error event: Error: getaddrinfo ENOTFOUND - AWS ElasticCache

Hey guys, did anyone have some issue like that to connect in the AWS ElasticCache in the ECS Container?

[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND cursobeta-dev-elasticache-redis.ilg7lv.ng.0001.use1.cache.amazonaws.com

Looks like permision, right?

const pubClient = new Redis({ host: process.env.AWS_REDIS_HOST, port: 6379 });

About this issue

Most upvoted comments

Try setting family: 6; for some reason ioredis defaults to family: 4 and AWS may be using (only) IPv6. Note I had the same issue on fly.io.

For anyone who may concern, you can also append the family=6 option to the redis URL (if you canโ€™t add family:6). For example, it should changeredis://domain:6379 to redis://domain:6379/?family=6.

Nothing helps ๐Ÿ˜ฆ

Any update here ? I am stuck in the same problem

thanks @richiejp ! In my case fly io was also working only with family: 6.

@richiejp thank you!!! This helped me out ๐Ÿ˜„

Just FYI, this works for me if I use add those options.


const pubRedisClient = new Redis(
	parseRedisCredentials(process.env.REDIS_CONNECTION ?? 'redis://localhost:6379', {
		lazyConnect: true,
		connectTimeout: 15000,
		retryStrategy: (times) => Math.min(times * 30, 1000),
		reconnectOnError(error) {
			const targetErrors = [/READONLY/, /ETIMEDOUT/];
			logger.warn(`Redis connection error: ${error.message}`, error);
			return targetErrors.some((targetError) => targetError.test(error.message));
		},
	}),
);