0

not able to get my Redis cluster and DynamoDB working together in the same lambda, if I comment any one other work fine, but together they will give timeout, and Cloudwatch simply does not log anything,

ex dyamodb.get_item(), redis.get() keep on running if I use both until lambda timed out the snippet below

redisclient = redis.Redis(host="redisclxxxxxxxxx.use.cache.amazonaws.com", port=6379, db=0,decode_responses=True)

redisclient.get('name')

table = db.Table('xxxxxxxxxx')
table.get_item(Key={'phoneno': phone, })

            def login(event, context):
                password = json.loads(event['body'])['password']
                phone = json.loads(event['body'])['phone']
                table = db.Table('xxxxxx')
                resp = table.get_item(Key={'phoneno': phone, })
                if 'Item' in resp:
                    if resp['Item']['password'] == password:
                        payload = {'phone': phone, 'password': password}
                        response = {"statusCode": 200, "body": json.dumps({'token': getToken(payload)})}
                    else:
                        response = {"statusCode": 200, "body": json.dumps({'error': 'password not match'})}
                else:
                    response = {"statusCode": 200, "body": json.dumps({'message': 'user_not_found sign up now'})}
                return response


            def getToken(payload):
                payload['exp'] = datetime.now() + timedelta(minutes=5)
                redisclient = redis.Redis(host="redisxxxxxxxxxx.xxxxxxx.cache.amazonaws.com", port=6379, db=0,
                                          decode_responses=True)
                redisclient.get('name')
                
                token = jwt.encode(payload, "xxxxxxxxxxxxxx", algorithm="HS256")
                redisclient.set(token,token)
                print(redisclient.get(token)+'redis')
                return token
Borislav Stoilov
  • 3,247
  • 2
  • 21
  • 46
Un_stuck
  • 1
  • 1

1 Answers1

0

Want to raise a point that's not discussed in the comments The timeout maybe due to the lambda function timeout configuration. Increase the lambda timeout configuration.

enter image description here

Msvstl
  • 1,116
  • 5
  • 21
  • tried that too for 30 sec still no solution – Un_stuck Nov 11 '22 at 12:01
  • @Un_stuck How much time the response is taking when you use them individually? – Msvstl Nov 11 '22 at 12:51
  • @Un_stuck api gateway has a limit of 30 seconds, so you will need to have both of these executed within 30 seconds. Verify both response times of only dynamodb and only redis. You will find the issue. – Msvstl Nov 11 '22 at 12:55