Trying to connect to redis running on ec2 instance locally but getting error despite all traffic inbound

+1 vote

The redis is running in the ec2 instance via daemon

ps aux | grep redis-server
redis     1182  0.0  0.8  38856  8740 ?        Ssl  21:40   0:00 /usr/bin/redis-server 127.0.0.1:6379

netstat -nlpt | grep 6379
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::6379                 :::*                    LISTEN      1388/redis-server *

Temporarily I have set network inbound to all traffic so it is likely not a problem of network security.

Type         Protocol Port Range   Source      Description
All traffic  All      All          0.0.0.0/0

But when I try to access from the python side:

import redis
r = redis.StrictRedis(host='ec2-xx-xxx-xx-xx.compute-1.amazonaws.com', port=6379, db=0)
r.set('foo', 'bar')
r.get('foo')

I get the following error:

ConnectionError: Error 111 connecting to ec2-xx-xxx-xx-xx.compute-1.amazonaws.com:6379. Connection refused.

What may cause such issue despite network inbound is open to all traffic and redis running fine in the ec2 instance ?

Sep 26, 2018 in AWS by bug_seeker
• 15,520 points
5,570 views

1 answer to this question.

0 votes

Your redis is not listening for connections from outside, instead it listening for local connections only.

tcp        0      0 127.0.0.1:6379 

Following works for Ubuntu. Edit /etc/redis/redis.conf and bind it to 0.0.0.0:

# bind 127.0.0.1
bind 0.0.0.0

and then restart the service:

sudo service redis-server restart

WARNING: Do not allow 0.0.0.0 in your security group. Anyone is allowed. Instead allow only specific IPs or CIDRs.

answered Sep 26, 2018 by Priyaj
• 58,100 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Using Shapely on AWS Lambda with Python 3

For some reason, the pip install of ...READ MORE

answered Oct 8, 2018 in AWS by Priyaj
• 58,100 points
2,935 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP