Tiago Costa
Tiago Costa

Reputation: 1016

How connect in Redis with Auth/Password NodeJs for AWS Lambda?

I am making a lambda function for validations tokens in AWS Api Gateway. However, I need to connect with the redis with security, but ever fails with this config:

var client = require('redis').createClient({
      host : 'redis-dev.amazonaws.com',
      port : 6379,
      no_ready_check: true,
      auth_pass: 'mypassword#c$blx!Na'                                                                                                                                                    
});

Error:

{ "errorMessage": "2018-06-08T17:55:38.344Z 23a4f9da-6b45-11e8-abe5-6119b1378dff Task timed out after 5.01 seconds"}

Any can help me?

Upvotes: 2

Views: 4712

Answers (2)

Can Sahin
Can Sahin

Reputation: 1166

As said by others VPC can be the issue, but there is another thing coming to mind.

Is this timeout a redis connection timeout or Lambda timeout ? Because, redis connections keeps the nodejs loop busy. And Lambda is by default waits for everything to clear up.

If so, try setting context.callbackWaitsForEmtpyEventLoop = false at the function handler. Or before the callback kill the redis connection.

Upvotes: 1

winter
winter

Reputation: 144

The error message looks like lambda is running in a subnet/vpc which doesn’t have outbound access to the redis server. Try one of 2 options to find the root cause

1- try running the code from your local machine and check if you can connect to redis server.

2- remove vpc setting in the lambda to execute lambda outside vpc .

Upvotes: 1

Related Questions