AWS - Connect to RDS via EC2 tunnel - postgresql

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.

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.

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?
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.

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

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.

connecting springboot application running locally to db instance running on aws VM instance

I have written a set of APIs using springboot framework. Locally its working fine. But now I am trying to test it with the postgresql database running on ec2 instance on aws.
NOTE: I am not using amazon RDS services, I have created an ec2 instance and installed postgres and configured database there.
I can see this exception being thrown when I am running my springboot application locally.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:297)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
This is the config from application.properties for one of the db
spring.xyz.datasource.jdbc-url=jdbc:postgresql://xyz.com:5432/xyz_db
spring.xyz.datasource.username=xyz
spring.xyz.datasource.password=xyz123
Am I not being able to connect because of the EC2 instance security configs ? How can I change that ?
Also it will be helpful if someone can tell me how can I make aws ec2 instance to accept the connection from only one VM ?
regarding Postgress connection-
add below rule to security group of Ec2 instance , on which you have installed postGress
Allow inbound traffic to postgress port from 0.0.0.0/0 and test. ( protocol- TCP, port - 5432, IP - 0.0.0.0/0)
regarding allow from only one VM
add security group rule to your Ec2 instance
Allow inbound traffic from your VM IP only

How can i connect with mongodb in SlamData for my EC2 server

I can successfully connected with mongodb on SlamData but for my localhost. Now I have a mongodb database on my EC2 server that database i want to connect in Ec2 then How can I ?
I know username and password. What should be a host and port?
If you are running Slamdata on your host and want to connect to MongoDB running on a remote EC2 host.
Then apart from the username and password, the host is the Public IP or host FQDN [ec2-xxxxxxx], port is 27017. For this check if your mongos is running and binding on 0.0.0.0. If it is binding to 127.0.0.1, you cannot connect remotely
Also check you AWS security group for EC2 and see that the port 27017 is open for your IP or in general to all [0.0.0.0] (this is NOT recommended!!!)
You can also review the FAQ on docs.slamdata.com located here.
Provides step-by-step troubleshooting for connecting to cloud-hosted MongoDB servers.
Additionally, the Path value refers to path inside of SlamData rather than the operating system path. For instance entering a value of aws1 results in a query path similar to the following, assuming you have a databased named demo and a collection named coll1:
SELECT * FROM `/aws1/demo/coll1`