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 Answers
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
EXPERT
answered 9 months ago
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
EXPERT
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions