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.

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
전문가
답변함 10달 전
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
전문가
답변함 10달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠