Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure security groups to connect to postgres RDS via client psycopg2

I am trying to connect to an AWS postgresql RDS via psycopg2. When I set my inbound rules on my security group to accept all traffic via postgresql on port 5432, I am able to connect.

However, when I constrain my inbound rule for postgresql on this port to accept traffic only from my client IP, I cannot connect and it times out. I get the error:

psycopg2.OperationalError: could not connect to server: Connection timed out Is the server running on host "[hostname]" ([some IP address]) and accepting TCP/IP connections on port 5432?

Thanks for any advice. I have tried configuring the inbound rules on my security group for my RDS instance to accept my client IP, my ec2 Instance private IP, and the IP address given in the error above, but no joy. Only accepting all traffic works. Any advice on what I'm doing wrong?

Thanks!

like image 716
ouonomos Avatar asked Oct 30 '22 04:10

ouonomos


2 Answers

Identify your IP from this link: https://www.whatismyip.com/. In the security groups, enable inbound rule to this IP followed by /32.

Example, if your IP from the above link comes as 192.168.0.25, then in security groups, add 192.168.0.25/32 as the source.

like image 111
krishna_mee2004 Avatar answered Nov 15 '22 06:11

krishna_mee2004


In my case, I found the answer was to configure an elastic IP so that it would have a constant value that could be accepted by my RDS security group. Perhaps other posters took it for granted that I had done so; I didn't know that was was part of the solution. Thanks for everyone's advice.

like image 35
ouonomos Avatar answered Nov 15 '22 06:11

ouonomos