Amazon Aurora Serverless is an on-demand, auto-scaling configuration for Amazon Aurora. It automatically scales compute capacity up or down based on your application's needs.
An Aurora Serverless DB cluster resides in the private subnet of Amazon VPC. You can’t give an Aurora Serverless DB cluster a public IP address. You can only access it from within a VPC.
If you want to access your Amazon Aurora Serverless DB cluster from MySQL Workbench, one way to do this is via an SSH tunnel through a bastion host (jump box).
In this post, I will share the steps for setting up a bastion host using an Amazon EC2 instance. Then use MySQL Workbench to connect to the bastion host via an SSH tunnel.
For this, you will perform the following steps:
- Setup networking configurations in Amazon VPC
- Create and launch an Amazon EC2 instance
- Configure MySQL Workbench
You should have the following prerequisites:
- Amazon Aurora Serverless DB cluster with MySQL-compatible edition
- MySQL Workbench installed in your local machine
Step 1: Setup networking configurations in Amazon VPC
- Open the Amazon VPC console
A. Security Group
Create a security group for Amazon EC2 within the same VPC where your Amazon Aurora Serverless DB cluster resides and add the following inbound rule:
Port Range: 22
Source: Enter the IP address of your local machine or choose My IP
B. Internet Gateway
- Create an Internet Gateway and attach it to your VPC
- Create subnets in the same Available Zone (AZ) as the subnet group of your DB cluster
D. Route Table
- Create a routing table
- Associate the created subnets in the routing table
- Add a route in the routing table that directs internet-bound traffic to the internet gateway
Note: If a subnet is associated with a route table that has a route to an internet gateway, it is now a public subnet.
Step 2: Create and launch an Amazon EC2 instance
- Open the Amazon EC2 console and choose Launch instances
- Select an Amazon Machine Image (AMI). In this example, I will choose an Amazon Linux 2 AMI
Choose Next: Configure Instance Details and make sure to use the following settings:
Network: Choose the VPC that the Amazon Aurora Serverless DB cluster uses
Subnet: Choose a public subnet (the subnet that has an internet gateway in its routing table)
Auto-assign Public IP: Enable
Choose Next: Add Storage and modify storage as needed
Choose Next: Add Tags and add tags as needed
Choose Review and Launch
After downloading the key pair, click on Launch Instances
Step 3: Configure MySQL Workbench
In Setup New Connection, enter a name for your connection and select Standard TCP/IP over SSH for the Connection Method
In the Parameters section, enter the following settings:
SSH Hostname: Enter the public IP address of your EC2 instance
SSH Username: Enter the username for your EC2 instance. In our example, we will use "ec2-user" (this is the default username for EC2 Linux machines)
SSH Key File: Select the private key (.pem file) that was downloaded when the EC2 instance was created
MySQL Hostname: Enter the Aurora Serverless DB cluster endpoint
MySQL Server port: Enter 3306
Username: Enter the username that you use to connect to your of the Aurora Serverless DB cluster
Password: Enter the user’s password of your Aurora Serverless DB cluster
Click on Test Connection
In the Setup New Connection, choose OK again to save the connection
Congratulations! You are now able to connect to your Amazon Aurora Serverless MySQL DB cluster from MySQL Workbench.