is it possible to connect to AWS RDS db instance(postgres) through ubuntu server installed out of aws(in my local)? - postgresql

Actually i have to migrate the data from AWS RDS postgres to on premises postgres.
For this i have to establish connectivity between my AWS RDS db instance and on premises(ubuntu server).
I have already configured the inbound rules of security group in my RDS DB instance. But still i am not able to connect to AWS RDS db instance directly through my Ubuntu Machine..
Is there any issue with the firewall of my VM??
Error which i am getting:
psql: error: could not connect to server: Connection timed out
Is the server running on host "XXXXXX" (X.X.X.X/X) and accepting
TCP/IP connections on port 5432?
The database setting for publicly accessible is set to NO.
There are both public as well as private subnet associated with my RDS instance.
i have provided the type as postgreSQL , port 5432 , protocol TCP, source custom ip (X.X.X.X/32)
Any help will be much appreciated.

To access an Amazon RDS database from the Internet:
Set the database to Publicly Accessible = Yes (This resolves the DNS name to a Public IP address)
Put the database in a Public Subnet (Mixing public & private subnets in a Subnet Group is not advisable, because the results will be random! It will only be in one subnet at any time, but might change subnets when upgraded or failover is triggered.)
Add a Security Group that allows Inbound access on the appropriate port (PostgreSQL = 5432) from your IP address
Reference the database via its DNS Name shown in the Amazon RDS management console
Alternatively, keep the database in a Private Subnet and access via a VPN Connection or by Port Forwarding via a Bastion Server.

Related

Connecting Tableau to a RDS DB in private tier using web proxy

I have the following architecture in AWS where the RDS DB is publicly unavailable and is inside a private subnet and I am currently connecting to the database through a ec2 jump box located in the public subnet using ssh port forwarding.
To connect to RDS we have two options.
SSH port forwarding setup on EC2
Web Proxy on EC2
I am able to connect using the SSH port forwarding option but I am not able to use Tableau as there is no option in Tableau to connect using .pem file which is required for SSH port connection to go through.
I am trying to see if there is documentation that will explain step by step on the process for setting up web proxy on the EC2 so that I can connect Tableau Desktop with the Database using the Elastic IP of the EC2 instance. Any help appreciated.

Cannot connect to RDS PostgeSQL instance

I have just created a new RDS instance with PostgreSQL but I cannot connect to it. I'm using the following command to connect:
psql --host=<dbendpoint> --port=5432 --username=<user> --password --dbname=<dbname>
I have been searching for information related to the problem, but none of the solutions have worked.
I have public access to the DB enabled.
I have allowed all traffic in the security group of the database.
The error I'm getting is this one:
psql: error: could not connect to server: Connection timed out
Is the server running on host "database-test-1-by-hand.cwsxzm3kzzim.us-west-1.rds.amazonaws.com" (204.236.171.212) and accepting
TCP/IP connections on port 5432?
Any idea about what's happening?
Update
Here are the options from the VPC the database is on:
I remember enabling the DNS hostname to allow public access.
Update 2
I have created an EC2 instance in the same VPC where the db instance is, and I have been able to connect to it.
The db instance is deployed in the same VPC, where I have 4 different subnets, two public and two private. This is the configuration:

AWS RDS "pg_hba.conf rejects connection for host"

I am working on setting up a Postgres instance on AWS through RDS. It has been placed into a VPC with a private subnet where the subnet CIDRs are: ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"].
I have a public subnet and have successfully connected to postgres through a bastion node from public to private subnet and run queries through SSH port forwarding.
However, now I am trying to setup a connection from a lambda that lives in the same private subnet of the VPC. The lambda has access according to the security group, but I receive the following error:
OperationalError: (psycopg2.OperationalError) FATAL: PAM
authentication failed for user "service_worker" FATAL: pg_hba.conf
rejects connection for host "10.0.23.73", user "service_worker",
database "myDB", SSL off
I have connected successfully with service_worker through the bastion, but for some reason I can't do so through lambda. It seems like Postgres is rejecting this particular host. And I can't find any configuration or documentation that specifies how to change what RDS does when managing this information in the pg_hba.conf file.
Does anyone have any insight into telling Postgres that a connection from a host in the same subnet is ok? I'm assuming there is some security policy that I'm somehow missing in the mix of all this.
Thanks!
It turns out that
Role-based authentication is currently not supported for Amazon RDS
for PostgreSQL and Aurora PostgreSQL.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html
And because Lambdas inherently use role based auth, this fails.

connect to postgres rds instance with pycharm db manager

I am struggling to connect with pyCharm to a postgres instance running on amazon rds.
In host I plug in the Endpoint. I configure driver to be the jdbc jar file (external library).
Test connection says that the connection on port 5432 is refused: Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
On rds side:
For the security group I have an inboud rule for All traffic with source Anywhere
The VPC has DNS resolution and DNS hostnames enabled
VPC is publicly accessible
VPC classic link is enabled

AWS - Connect to RDS via EC2 tunnel

My RDS is in a VPC, so it has a private IP address. I can connect my RDS database instance from my local computer with pgAdmin using SSH tunneling via EC2 Elastic IP.
Now I want to connect to the database instance in my code in python. How can I do that?
Point your python code to the same address and port you're using for the tunnelling.
If you're not sure check the pgAdmin destination in the configuration and just copy it.