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
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.