Connect Postgres RDS instance from local Database client - amazon-web-services

I have a Postgres RDS instance running in a private Subnet. It is accessible through a EC2 as a bastion host, as EC2 instance is configured in a public subnet in the same VPC as the private subnet. I can ssh to the RDS instance through the jump server.
Is there a way I can DBeaver client to the RDS instance? Do I need to configure a VPN connection for that? What are the different options here?

You can stablish a connection to the DB through the jump server using SSH Tunnel:
Create new connection
Configure SSH settings using the fields of the bastion host (use password or private key)
Specify PostgreSQL user/password/endpoint and test the connection

Related

How to connect my developer machine with Amazon Memory DB Cluster

Memory DB Cluster configured, connected with an EC2 instance within same VPC. but cannot telnet Memory DB Cluster even when connected via vpn where as from EC2 instance, telnet and redis-cli both works.
Configured VPN via OpenVPN and connected. I can access EC2 instance [telnet etc] via private IP when connected with VPN, but could not connect with Memory DB cluster. need to connect my developer machine to be connected with DB Cluster to proceed.
tried to find any private IP of cluster or something by which i can connect but couldn't.
Instead of VPN it would be easy to do ssh tunnelling to do port forwarding for development purposes . Create a bastion host and ssh tunnel and forward the Memory db port. you can follow the instructions which were done for RDS port forward https://aws.amazon.com/premiumsupport/knowledge-center/rds-connect-using-bastion-host-linux/

how to connect a RDS outside VPC securely?

we want to our RDS outside VPC openly access, but it is not secure to do so.
Is there any solution to help us connect the RDS securely ?
You have two basic options to access an Amazon RDS database. Which you choose depends on your Risk appetite.
Option 1: RDS database in public subnet
For this option, the database is launched in a Public Subnet, with Publicly Available = Yes.
To secure the database, you would configure the Security Group to only permit inbound access from your IP address.
Option 2: RDS database in private subnet
For this option, the database is launched in a Private Subnet, with Publicly Available = No.
You will need some way to 'connect' to the VPC, and then connect to the RDS database. Options for connecting to the VPC could be:
Create an AWS Client VPN, which allows you to connect to the VPC from any location using an OpenVPN-based VPN client, or
Launch an Amazon EC2 instance in the public subnet and connect to it using SSH and Port Forwarding (See: How to use SSH Tunnel to connect to an RDS instance via an EC2 instance?)

JDBC connection to mySQL RDS instance in a private subnet

We are trying to find out ways to make a JDBC connection to a SQL Server hosted in a private EC2 instance or a private subnet.
Basically, we have an Excel-based small BI report that connects to an On-Prem SQL server and we want to move that DB to cloud and just switch the end points.
There is a lot of information out there about SSH connections to a private subnet RDS SQL server through bastion hosts etc, but I have not found anything related to direct connection.
Due to the infra set up, VPN and direct connect is not possible to use and the users will be directly connecting to private RDS instance over a public internet.
I have not found anything related to direct connection.
Without VPN or Direct Connect, direct connection is not possible. Your RDS is in private subnet, as there is no direct internet connectivity to it - thus the name "private".
If you don't want to use VPN and/or don't have Direct Connect, then the only option is to use ssh tunnel through a bastion host as explained by AWS:
How can I connect to my Amazon RDS DB instance using a bastion host from my Linux/macOS machine?

Can not connect to my Redshift cluster in private subnet

I have set up a VPC using a suggested approach as discussed on Linux Bastion Host Quick Start.
I have also created a Redshift cluster in one of private subnets and also created its dedicated security group with no rule restrictions. That is for both inbound and outbound rules for Redshift I am assigning all traffics and ports (0.0.0.0/0). I am even doing the same for the public EC2 instance on public subnet.
I can successfully ssh to my public bastion instances but from there I can not telnet to my Redshift endpoint.
[ec2-user#ip-10-0-141-20 ~]$ telnet ******.redshift.amazonaws.com 5439
Trying 10.0.20.169...
Connected to ******.redshift.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
I am not sure what is wrong with my configurations. In Redshift I have disabled both public access and VPC routing.
I assume that your situation is:
You have an Amazon Redshift cluster in a private subnet
You have a Bastion server in a public subnet of the same VPC
You wish to connect an SQL Client on your computer to the Redshift cluster
A way to do this would be:
Use Port Forwarding to connect to the Redshift cluster via the Bastion host
If you are using a Linux/Mac:
ssh-add keypair.pem
ssh -A ec2-user#BASTION-IP -L 5439:xyz.redshift.amazonaws.com:5439
(This says: Forward local port 5439 to the bastion, where is should send traffic to the Redshift cluster on port 5439)
If you are using Windows, then you can use Pageant and PuTTY
Then, configure your SQL Client to connect to Redshift with server=localhost and port=5439, together with your login credentials
If the above does not work, some things to check:
The Security Group on the Redshift Cluster should allow inbound connections on port 5439 from the Bastion (or from the whole VPC or from 0.0.0.0/0
The outbound rules on the Bastion should remain at their default setting of allowing all outbound traffic
If things are still going wrong, you can test the Redshift connection by installing psql on the Bastion and attempting a connection to Redshift. (Redshift was forked from PostgreSQL, so it behaves similarly).

PgAdmin access to AWS Postgres instance in private subnet

I'm trying to create a realistic network setup for a multi-tiered web application. I've created a new VPC within AWS with 1 x public subnet & 2 x private subnet. I then created a Postgres instance within the private subnet and set it to not publicly accessible. This adds an extra layer of security around the database, but how do I then access the database from my local IP?
I created a security group & assigned my IP to the inbound rules & assigned that to the DB instance during creation:
But I still have no way of connecting to it? Do I need to create a VPN and connect to my VPC via the VPN and then connect to the DB instance? Within the proposed architecture, how do you connect to the DB?
What I'm trying to achieve is an architecture which will allow me to create Lambda functions which communicate with the DB via the API Gateway and serve data to a web frontend. So I want the DB protected via the private subnet. But I also want to be able to connect directly to the DB from my local laptop.
At the moment - the RDS instance is running in the VPC, but I don't know how to connect to it. DoI need to set up an Internet Gateway / VPN / EC2 instance and jump to the DB?
You have implemented excellent security by placing the Amazon RDS database into a private subnet. This means it is not accessible from the Internet, which blocks off the majority of potential security threats.
However, it also means that you cannot connect to it from the Internet.
The most common method to achieve your goals is to launch an Amazon EC2 instance in the public subnet and use it as a Bastion or Jump Box:
You SSH into the Bastion
The Bastion can then connect you to other resources within the VPC
Since you merely wish to connect to a database (as opposed to logging into another server), the best method is to use SSH with port forwarding.
In Windows, this can be done using your SSH client -- for example, if you are using PuTTY, you can configure Tunnelling. See: How to Configure an SSH Tunnel on PuTTY
For Mac/Linux, use this command:
ssh -i YOUR-KEYPAIR.pem -L 5555:RDS-ENDPOINT:5432 ec2-user#YOUR-BASTION-SERVER
You then point the SQL client on your laptop to: localhost:5555
The 5555 can be any number you wish. It is merely the "local port" on your own computer that will be used to forward traffic to the remote computer.
The RDS-ENDPOINT is the Endpoint of your RDS database as supplied in the RDS console. It will be similar to: db.cnrffgvaxtw8.us-west-2.rds.amazonaws.com
BASTION-SERVER is the IP address or DNS name of the Jump Box you will use to connect
Then, any traffic sent to localhost:5555 from your SQL client will be automatically sent over the SSH connection to the Bastion/Jump Box, which will then forward it to port 5432 on the RDS database. The traffic will be encrypted across the SSH connection, and establishment of the connection requires an SSH keypair.
I referred a lot of articles and videos to find this answer.
yes, you can connect to rds instances in private subnets
we have two ways to connect
With server: By using ec2 in the public subnet and using it as a bastion host. we can connect to pg admin by ssh tunneling
Serverless: By using client VPN endpoint. create a client VPN endpoint and associate the subnets and allow the internet to the private subnets. and then download the configuration file and install open VPN GUI and import the configuration file and add the keys and then connect the open VPN. Now try to connect to pgadmin, it will connect.
for steps: https://docs.google.com/document/d/1rSpA_kCGtwXOTIP2wwHSELf7j9KbXyQ3pVFveNBihv4/edit )