Python Lambda Function Cannot Access MemoryDB

0

Hello, I'm trying to write a Python 3.11 lambda function that will talk to Amazon MemoryDB. When I include the redis connection and a simple "get", the function hangs and times out after a few seconds.

Things I've ensured:

  • Lambda function is running on the same VPC as MemoryDB
  • Security Group for both Lambda and MemoryDB are both set to allow Inbound and Outbound 6379.
  • Lambda function and MemoryDB are in the same subnet

The cluster endpoint looks like this: clustercfg.my-cluster-name.xyz123memorydb.us-east-2.amazonaws.com:6379

My connect and get look like this:

import json
import redis

r = redis.Redis(host='clustercfg.my-cluster-name.xyz123memorydb.us-east-2.amazonaws.com', port=6379, decode_responses=True)
r.set('foo', 'bar')

Running the above hangs for a few seconds, times out and then dies. The lack of ability to do simple things like pinging or CLI connection to redis from the "host" that the function runs on makes it hard for me to troubleshoot. Any ideas on where I can start to troubleshoot here and how to fix this issue?

Thanks! -Brett

  • Hi there.

    Could you share what the Lambda execution role looks like? You may need permissions to access MemoryDB.

已提問 9 個月前檢視次數 379 次
2 個答案
0

Please check lambda function settings.

  1. Go to Configuration
  2. General -> Timeout.

I hope that's not the case but your function would be timed out if that timeout limit reaches first before connecting to memory DB. Since there are few things, which you have already mentioned here, so network connectivity shouldn't be the problem.

I'd suggest you to follow this AWS Documentation, this may help you.

Comment here how it goes, happy to help.

Abhishek

profile pictureAWS
專家
已回答 9 個月前
0

I think this is the problem:

Security Group for both Lambda and MemoryDB are both set to allow Inbound and Outbound 6379

The security group on MemoryDB needs to allow inbound connections on port 6379. Outbound from MemoryDB is unimportant unless it is establishing connections to somewhere.

profile pictureAWS
專家
已回答 9 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南