Access public PostgreSQL server (Amazon RDS) from personal computer through proxy

Viewed 437

I'm new to Amazon Web Service (AWS).
I already created a PostgreSQL from AWS RDS:

  • Endpoint: database-1.XXX.rds.amazonaws.com
  • Port: 5432
  • Public accessibility: Yes
  • Availablity zone: ap-northeast-1c

After that, I will push my application that using the database to AWS (maybe deploy to EKS).
However, I want to try testing the database server from my local computer first.

I haven't tried testing from my laptop PC at home yet, but I think it will connect OK because my laptop PC is not using the HTTP proxy to connect to the network.

The problem is that I want to try testing from my company PC, which needs setup the HTTP proxy to connect to the internet. The PC spec:

  • Windows 10
  • Installed PostgreSQL 10

Firstly, I tried using psql command-line:

psql -h database-1.XXXX.rds.amazonaws.com -U postgre
>  Unknown host

set http_proxy=http://user:password@my_company_proxy:3128
set https_proxy=http://user:password@my_company_proxy:3128
psql -h database-1.XXXX.rds.amazonaws.com -U postgre
>  Unknown host

set http_proxy=http://my_second_company_proxy:3128
set https_proxy=http://my_second_company_proxy:3128
psql -h database-1.XXXX.rds.amazonaws.com -U postgre
>  Unknown host

Then, I tried using the pgAdmin tool.

enter image description here

As from the internet post, it said that we can use "SSH Tunnel" for inputing proxy:

enter image description here

However, the error message will be shown:

enter image description here

So, anyone can help suggest if we can connect to the public PostgreSQL server through HTTP proxy?

3 Answers

I think problem is Postgres uses plain TCP/IP protocol and you are trying to use HTTP proxy. Also you're trying to create SSH tunnel against your HTTP proxy server which won't work.

So I'd suggest following solutions:

  1. Use TCP proxy instead of HTTP proxy
  2. Create an EC2 or any instance that has SSH access from your company network and has access to public internet. So that you can create SSH tunnel through that instance to achieve your goal.

NOTE: Make sure you PostgreSQL is accessible from public internet (although this is usually bad idea, but it's out of scope this question) sometimes security group configs prevent it to connect from public internet.

Just add all ports(5432,3128...) in the Security Group from your RDS and specify your IP. Don't forget "/32"

enter image description here

Let me add that "unknown host" is usually an indication that you're not resolving the DNS hostname. Also, your HTTP proxy should not interfere with connections to databases since they aren't on port 80 or 443. A couple of things you can try (assuming you're on windows) sub in your actual url:

nslookup database-1.XXXX.rds.amazonaws.com
telnet database-1.XXXX.rds.amazonaws.com 5432

You should also check the security group that is attached to your RDS and make sure you've opened up the ip address that you're originating from on port TCP/5432.

Lastly check that your VPC has DNS and Hostnames enabled. https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html#vpc-dns-updating

Related