1

I am able to access my RDS instance through my EC2 instance through

 psql -U user -h hostname  $DBname

I want to know how the RDS connects to EC2. is it private IP or public IP or Hostname

my developer has configured my private IP in connection http://privateip:5000 in the backend (don't what exactly it)

When I use this command:

 curl --location --request GET 'http://localhost:5000/api/Supplier

I am able to access the API response.

but when I use my

 curl --location --request GET 'http://privateip:5000/api/Supplier

I get curl: (7) Failed to connect to privateIp port 5000: Connection refused

I am sure my EC2 can connect to RDS .

Maybe my understanding of this is limited.

could any one help me out of this ?

My RDS SG

All TCP TCP 0 - 65535 Custom sg-EC2

PostgreSQL TCP 5432 Custom 0.0.0.0/0

PostgreSQL TCP 5432 custom sg-Ec2

All UDP UDP 0 - 65535 Custom sg-EC2

All ICMP - IPv4 ICMP 0 - 65535 Custom sg-EC2
Chris Williams
  • 32,215
  • 4
  • 30
  • 68
sumanth shetty
  • 1,851
  • 5
  • 24
  • 57

2 Answers2

1

Rule of thumb for checking SG of instance telnet privateip 5000 if the port is not open it clearly indicate that EC2 instance security group not allowing the port.

Then open 5000 from SG of the instance.

If the above fix does not resolve the issue then it might be the case that application only listening on localhost so you need to allow 0.0.0.0 to work it private IP.

I am sure my EC2 can connect to RDS .

The issue is related to connecting with Ec2 instance not the RDS, you request curl --location --request GET 'http://privateip:5000/api/Supplier has nothing to do with RDS except DB connection. you application depend on Ec2 security group, not the RDS security group.

Adiii
  • 54,482
  • 7
  • 145
  • 148
1

If you're trying to connect to the private IP address from the instance itself you will need to ensure the following conditions are met:

  • Inbound access in the security group from the source of your instance to port 5000.
  • Outbound access allowed in the security group for your instance.
  • NACL is either the default NACL, or if you have made your own it is allowing inbound and outbound access including to ephemeral ports.

The source inbound rule for the security group should be scoped to one of the following:

  • Inbound from the private IP address range of the EC2 instance e.g. 10.0.0.1/32
  • Inbound from either a subnet or VPC range e.g. 10.0.0.0/16.
  • Inbound from the world e.g. 0.0.0.0/0 (Use with caution as this allows any server that can connect, to be able to connect on this port).
  • Inbound from a security group (either the same or different). e.g. sd-abcdef
Chris Williams
  • 32,215
  • 4
  • 30
  • 68