Zorgan
Zorgan

Reputation: 9123

Can't connect to my AWS Database Instance | psql: could not connect to server: Operation timed out

I created a postgres DB instance on AWS RDS. I am trying to connect this DB instance to my django zappa app so I can perform AWS Lambda functions.

I've added a new security group to my DB instance so I can allow my django app to connect to it:

enter image description here

My DB details show that the new security group is active:

enter image description here

However when I try to connect to it, either by running psql --host="*************.us-east-2.rds.amazonaws.com" --port="5432" --username="*********" --password --dbname="*****" via my terminal,

or via my pgadmin interface, it returns this error:

psql: could not connect to server: Operation timed out
    Is the server running on host "***********.us-east-2.rds.amazonaws.com" (18.191.94.44) and accepting
    TCP/IP connections on port 5432?

Any idea why it does this?

Upvotes: 5

Views: 7664

Answers (2)

mm_
mm_

Reputation: 1735

Check:

https://medium.com/overlander/connecting-to-rds-from-local-over-tcp-operation-timed-out-5cfc819f402c

Is our RDS instance able to send responses back to us? Check that your RDS instance is in a public subnet. A public subnet is one whose route table directs some traffic out to the public via an internet gateway. If you want to connect to an RDS instance from a public address, the instance must in a public subnet.

Upvotes: 2

ThomasVdBerge
ThomasVdBerge

Reputation: 8140

The most common error is not having allowed yourself access/not set to public accessibility.

  1. Ensure that the RDS DB instance was marked as publicly accessible (change to YES.

Select Yes if you want EC2 instances and devices outside of the VPC hosting the DB instance to connect to the DB instance. If you select No, Amazon RDS will not assign a public IP address to the DB instance, and no EC2 instance or devices outside of the VPC will be able to connect. If you select Yes, you must also select one or more VPC security groups that specify which EC2 instances and devices can connect to the DB instance.

  1. Make sure you've allowed yourself access in the Security Group of the RDS database. You should add or change the current inbound rule to allows your ip (or 0.0.0.0/0 as a last resort - anyone on the internet will be able to connect) to access the RDS on your port. By default the outbound rule is already set as 0.0.0.0/0

Upvotes: 13

Related Questions