Search code examples
amazon-ec2amazon-rdsamazon-vpcssh-tunnelaws-ec2-instance-connect

How to create a new SSH Key pair and assign it to an EC2 instance which currently does not have one?


I am trying to connect to an AWS RDS MySQL instance (private subnet) via MySQL Workbench. My VPC contains:

  • EC2 instance (public subnet)
  • RDS instance (private subnet)

I can access the RDS via EC2 but cannot connect to the RDS instance via my local machine. From what I understand, this is because I do not have a SSH key pair.

The EC2 instance was created when I created an ElasticBeanstalk application which hosts a REST API. It appears that an SSH key pair was not created. Without an SSH Key I cannot access the RDS instance from my local machine.

How do I create a new SSH Key pair and assign it to my EC2 instance?

Settings required to connect to MySQL instance via Standard TCP/IP over SSH with MySQL Workbench: Settings required to connect to MySQL instance via Standard TCP/IP over SSH with MySQL Workbench

EC2 warning stating that I do not have an associated key pair. EC2 warning stating that I do not have an associated key pair

Any help would be greatly appreciated!


Solution

  • First of all, just to clarify for future readers, you cannot connect to RDS from your local machine—not because there isn't an SSH Key Pair, but because your RDS instance is located in a private subnet.
    In other words, even if you have associated a public IP with your RDS instance, you cannot connect to it because the route table for the private subnet does not route 0.0.0.0/0 traffic through an Internet Gateway.

    Having clarified that, if you want to connect to your private RDS instance, you can use your public EC2 instance as a proxy: to do so, you'll need a new SSH key.
    You have two options: