Connect to RDS instance via MYSQL workbench without a static IP - amazon-web-services

I have an RDS instance that only accepts incoming requests from my EC2 instance. I want to connect MySQLWorkbench to the RDS instance, however, I use a VPN, and don't want to allow a specific IP address access to the RDS, as my local IP address changes frequently. Can I connect to my RDS instance using a PEM key or similar approach?

Yes, MySQL Workbench allows you to connect to databases using Standard TCP/IP over SSH
Since you've got an EC2 instance running, simply use the EC2's public IP, username and you can use the PEM as an authentication method.
ssh -o "ExitOnForwardFailure yes" -p 22 -fN ec2-user#123.456.789.XXX -L localhost:3360:rds-conn-url:3306
This is a non-login shell (N) so your terminal will hang when connected.
Alternatively, if you're using a Unix based system, you can make SSH tunnel to the EC2 instance and then use the port binding with Standard TCP/IP 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/

SSh AWS Ec2 instance

I want to SSH AWS EC2 instance but by just only my computer, like SSH over the key. Only my computer can ssh into that instance. How can I configure it?
Thanks.
A common way to achieve that is to setup security group of your instance so that only your IP can access the instance:
Rules to connect to instances from your computer
As Marcin already answered, you should use security group to restrict access to your IP only. However, whenever you change the network, you have to manually edit that security group again.
One solution would be restrict access using mac address using firewall, something like this:
iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source xx:xx:xx:xx:xx:xx -j ACCEPT
iptables -A INPUT -p tcp --destination-port 22 -j DROP
A solution that doesn't require you to frequently update your security groups with your IP address is to use SSH through AWS Session Manager. Using SSH through Session Manager works exactly like a normal SSH connection. The SSH through Session Manager solution works by creating an SSH tunnel through your Session Manager connection. You can control access to your instance using IAM by restricting which AWS users can call StartSession on your EC2 instance. In your case, you can configure access to Session Manager only to the IAM User you configure on your computer.
You may even want to consider using Session Manager on it's own because that also allows you to connect to your instance and run commands... but using SSH through Session Manager gives you the security benefits of Session Manager and the familiarity of SSH. Session Manager allows you to connect to your EC2 instance without opening inbound ports on your security groups so it is more secure from a networking point of view especially if you have a publicly reachable instance. It uses normal HTTPS traffic so your instance will only need outbound access to the SSM Session Manager endpoints.
More details on how SSM Session Manager works here.

EC2 Instance Connect equivalent of scp

I have an EC2 instance on which I don't allow ssh.
I use EC2 Instance Connect to connect to it.
What is the alternative to scp Amazon exposes when using EC2 Instance Connect rather than ssh?
EC2 Instance Connect uses a web connection to Guacomole running on an AWS service, which then establishes an SSH connection on your behalf. There is no scp component available.
As an alternative, if you can establish a connection using AWS Systems Manager Session Manager, then it can also provide Port Forwarding that can be used for additional connections (such as scp).

How to access AWS EC2 instance from web browser on Linux machine?

When I try to connect to my EC2 instance using web browser (Mozilla Firefox) using the third option in the connect (EC2 Instance Connect (browser-based SSH connection) ), I get the following error in the new pop-up window:
There was a problem setting up the instance connection
Log in failed. If this instance has just started up, try again in a minute or two.
Some things to check:
Make sure the instance was launched from Amazon Linux 2 or Ubuntu 16.04 or later
Check that the instance is in a public subnet (defined as having a Route Table that points to an Internet Gateway)
Open the Security Group for SSH (port 22) either for the whole Internet (0.0.0.0/0) (which is a very poor choice for security) or from the IP address ranges for EC2 Instance Connect (See: AWS IP Address Ranges - AWS General Reference)
EC2 Instance Connect in your browser establishes a web connection to the AWS service. Then, the SSH connection is established from the AWS Service to the Amazon EC2 instance. This is why the security group needs to allow incoming connections from the IP address range associated with the EC2 Instance Connect Service (not your own IP address).
Alternative ways to connect are:
Run an SSH client on your computer, or
Use AWS Systems Manager Session Manager (which connects via an Agent running on the computer, so it's not 'real' SSH)

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 )