0
votes

So I have a python handler like this:

redisClinet = redis.StrictRedis(host = environ['REDIS_ENDPOINT'], port=6379, db=0)    

def handler(event, context):
    // some logic

    lastEvent = redisClinet.get('lastEvent')

    // rest of the logic

I have:

  • lambda vpc properly setup to be on the same vpc as Elasticache cluster, the security group allows everyting inbound/outbound
  • lambda execution role has access to all actions of all resources, including vpc, elasticache, etc.

When I run the function locally on my own machine, it properly exits quickly because Elasticache obviously refuses ip address of my machine, but the problem is that I can't even see the error message when I run it on lambda to see what's going on.

The Actual Question: So aside from the reason my lambda fails to connect to redis, how to get lambda properly log the error and quit on an error instead of waiting for 60 seconds and timing out?

1
Need some more information. What is the memory used by the Lambda function? Please confirm that the redis instance was created on that VPC and the security group chosen in the Elasticache Subnet Group is the one that allows all inbound/outbound. Also confirm that the Lambda is on the same VPC and subnets. Then up the memory and timeout to 300 seconds and try again. Could also enable "x-ray" in the Lambda Console and/or use Cloud9 (haven't used this yet) for a different take on what is happening in the Lambda.Zaxxon
@Aliweb, did you figure out why lambda / redis connection times out?Jun711
@Jun unfortunately notAliweb
@Aliweb It could be because of access permission of ElasticCache. Check out this aws tutorial: docs.aws.amazon.com/lambda/latest/dg/vpc-ec.html I just found this.Jun711

1 Answers

0
votes

Information provided is less.

Lambda might be timing out due to redis connection. You can increase lambda timeout(must be greater than timeout set in redis client) Or set your own connection timeout value in redis-py.

I think you can also move Redis connection part into lambda handler and pass it around. Put a try catch and print the logs in catch. Something like this:

def handler(event, context):
    try:
       redisClinet = redis.StrictRedis(host = environ['REDIS_ENDPOINT'], port=6379, db=0)
    except Exception as e:
        print e
    // some logic
    lastEvent = redisClinet.get('lastEvent')
    // rest of the logic