question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

timeout connecting to redis hosted on aws ElastiCache

See original GitHub issue

Hi,

I have a redis server hosted by aws using aws ElastiCache. When I try to connect to it using a lambda and on my local machine, it gives ‘timeout connecting to server’ error. However, my colleague could connect to this redis using another client in PHP. I wonder what I did wrong.

try:
        redisClient = redis.Redis(host='***.use1.cache.amazonaws.com', port=6379, db=0, socket_timeout=10)
        print(redisClient)
        try:
            print(redisClient.ping())
            print(redisClient.set('foo','bar'))
            # r.get('foo')
        except Exception as e:
            print('get set error: ', e)
    except Exception as e:
        print('redis err: ', e)

// redisClient Redis<ConnectionPool<Connection<host=***.use1.cache.amazonaws.com,port=6379,db=0>>>

// get set error:  Timeout connecting to server for ping or set

Without setting the socket_timeout parameter, it will time out based on redis-py operation timeout: Error 60 connecting to ***.use1.cache.amazonaws.com:6379. Operation timed out.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

22reactions
john-feusi-neurocommented, Jun 27, 2019

I ran into this issue as well, but from a Lambda. For me, there were a few problems that had to be ironed out

  • The lambda needs VPC permissions.
  • The ElastiCache security group needs an inbound rule from the Lambda security group that allows communication on the Redis port. I thought they could just be in the same security group.
  • And the real kicker: I had turned on encryption in-transit. This meant that I needed to pass redis.RedisClietn(... ssl=True). The redis-py page mentions that ssl_cert_reqs needs to be set to None for use with ElastiCache, but that didn’t seem to be true in my case. I did however need to pass ssl=True.

It makes sense that ssl=True needed to be set but the connection was just timing out so I went round and round trying to figure out what the problem with the permissions/VPC/SG setup was.

10reactions
211217613commented, Jul 21, 2018

When I try to connect to it using a lambda and on my local machine

  • You can only connect to elasticache via a machine running in the same region. It’s in the docs somewhere.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting - Amazon ElastiCache for Redis
The timeout is the time in seconds allowed for idle connections to persist. If the client doesn't submit any request in the period,...
Read more >
AWS Elasticache Timeout from EC2 - Stack Overflow
I had VPC setup, on the same network, could connect to redis on my local through OpenVPN and it was still timing out...
Read more >
timeout connecting to redis hosted on aws ElastiCache
I have a redis server hosted by aws using aws ElastiCache. When I try to connect to it using a lambda and on...
Read more >
AWS Elasticache Redis connection timed out - Laracasts
'redis' => [ 'client' => 'predis', 'redis' => [ 'host' => env('REDIS_HOST', '127.0.0.1'), // This is primary endpoint from elasticache settings 'password' => ......
Read more >
Ecs unable to connect to redis elasticache, timeout error!
Ecs unable to connect to redis elasticache, timeout error! · Both of them are in same vpc. · Redis has same subnet group...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found