0

I have a Redis cluster set up that I need to connect to from a Lambda function. I'm using the following code to create the client and connect to Redis:

const getClient = async (clientargs) => {
    var params = {
        no_ready_check: true,
        connect_timeout: clientargs.timeout == null ? 30000 : clientargs.timeout, 
        enable_offline_queue: false,
        db: clientargs.index,
        retry_strategy: undefined
    };
    logger.debug('db getClient: Connecting to redis client.');
    logger.debug('db getClient params', params);
    const client = redis.createClient(clientargs.host, clientargs.port, params);

    await client.connect(); 
    
    // do stuff once it's connected
}

clientargs.host stores the Elasticache Redis endpoint and I'm using the default port 6379. I've checked that the host and port are being passed in correctly to the getClient function, and that they are being passed into redis.createClient properly as well. I was originally debugging in a local environment and noticed that it was trying to connect to 127.0.0.1 instead of the Elasticache endpoint, so I ran a few tests within the AWS Console but it's still trying on 127.0.0.1:6379.

I have also tried passing the host and port arguments into the client.connect() function, but had no luck with that either.

The Lambda function and the Elasticache Redis cluster are in the same VPC instance and security group, so I don't think that is the issue, but I am fairly new to AWS as a whole so any help/thoughts would be appreciated!

  • This may be relevant https://stackoverflow.com/questions/66829776/redis-client-ignoring-configuration-options-set-on-it-and-trying-to-connect-to-d – Kai Light Apr 07 '22 at 02:03
  • 1
    @KaiLight I did end up just switching over to the ioredis library which has been working wonderfully. Thanks for the link though, that did help explain why the prior code wasn't working. – johncaseymcd Apr 19 '22 at 16:02

0 Answers0