João A. Veiga
João A. Veiga

Reputation: 575

Failed connection to postgres on EC2 only, works on local machine

I'm running an application on an EC2 instance (AWS cloud computing solution) that connects to a specific Database address.

When I run the application in my local machine it connects perfectly to the DB.

However, when I run it in the EC2 the connection hangs indefinitely. I've also tried to connect using psql to prove that the error was on the connection and received the "Connection timed out error".

Both my local machine and the EC2 instance are running ubuntu 22.04.

Does anyone have any idea what could be going on?

Upvotes: 0

Views: 163

Answers (1)

Hùng Nguyễn
Hùng Nguyễn

Reputation: 629

Both RDS instance and EC2 instance need to be in the same VPC, check your inbound rule of security group of your RDS. It must allow security group of your EC2 instance.

If you configured it to connect through public internet (not recommended) like what you did from local, the inbound rule of RDS need to allow IP of your EC2 instance.

Upvotes: 1

Related Questions