ioredis - ClusterAllFailedError: Failed to refresh slots cache

The following works for me.

Redis version: 5.0.4 on AWS ElastiCache Clustered with TLS and AUTH enabled.

ioredis version: 4.16.0

Code to connect:

const redis = new Redis.Cluster(
            [{ "host": <ELASTI_CACHE_CONFIGURATION_ENDPOINT> }], {
                dnsLookup: (address, callback) => callback(null, address),
                redisOptions: {
                    tls: true,
                    password: <ELASTI_CACHE_REDIS_AUTH>
                }
            });

When you launch ElastiCache, you will need to specify one or more Subnet Group (generally private Subnets) and the Security Group. When you run the above code from any compute (Lambda, EC2 etc.), you need to ensure the following

  • ElastiCache is reachable from your Compute (Put the compute in a Subnet which can communicate with the Subnet of the ElastiCache in the same VPC. If the compute and Elasticache are on different VPCs, ensure VPC peering enabled between them.)
  • Ensure the Security Group, NACL allows the connection to ElastiCache port (6379 is the default) from your Compute Subnet
  • Finally ensure the Compute can assume an IAM Role(EC2 instance profile, Lambda Role etc) which has appropriate access to ElastiCache. In case you are running on an EC2 instance, make sure your code uses the temporary credentials of the Role assigned in the EC2 instance profile.