Overview
Lab details
- This lab walks you through the steps of connecting Amazon EC2 with Amazon RDS Instance.
- We will create an EC2 instance inside a public subnet and an Amazon RDS in a private subnet group.
- Duration: 55 minutes
- AWS Region: US East (N. Virginia) us-east-1.
Architecture diagram

Task details
- Sign in to AWS Management Console
- Create an EC2 instance.
- Create an Amazon RDS instance.
- Create a connection to the Amazon RDS database from the EC2 instance.
- Create a Database, Table, and insert data for testing.
- Validation of the lab.
- Deleting AWS resources.
Launching the lab environment
- To launch the lab environment, Click on the Launch lab button.
- Please wait until the cloud environment is provisioned. It will take less than a minute to provision.
- Once the Lab is started, you will be provided with IAM user name, Password, Access Key, and Secret Access Key.
Lab guide
Lab steps
Task 1: Sign in to AWS Management Console
- Click on the Open console button, and you will get redirected to AWS Console in a new browser tab.
-
On the AWS sign-in page,
- Leave the Account ID as default. Never edit/remove the 12-digit Account ID present in the AWS Console. Otherwise, you cannot proceed with the lab.
- Now copy your Username and Password in the Lab Console to the IAM Username and Password in AWS Console and click on the Sign-in button.
- Once Signed In to the AWS Management Console, make the default AWS Region as US East (N. Virginia) us-east-1.
If you face any issues, please go through FAQs and Troubleshooting.
Task 2: Launch EC2 Instance
- Make sure you are in US East (N.Virginia) us-east-1 Region.
- Navigate to EC2 by clicking on the Services menu in the top, then click on the EC2 in the Compute section.
-
Navigate to Instances on the left panel and click on Launch instances.

- Name : Enter MyPublicServer

- For Amazon Machine Image (AMI): Search for Amazon Linux 2023 kernel-6.1 AMI in Quick Start menu.
-
For Instance Type: select t2.micro

-
For Key pair: Select Create a new key pair Button
- Key pair name: Enter WhizKey
- Key pair type: Select RSA
- Private key file format: Select .pem
- Select Create key pair Button.
- In Network Settings, Click on Edit:
- Auto-assign public IP: Enable
- Select Create new Security group
- Security group name : Enter MyEC2Server_SG
-
Description : Enter Security Group to allow traffic to EC2

-
To add SSH:
- Choose Type: SSH
- Source: Anywhere
-
For RDS:
- Click on Add security group role
- Choose Type: MySQL/Aurora
-
Source: Anywhere

-
Click on Advanced Details. Under the User data section, enter the following script, (which installs MySQL):
- Keep rest thing Default and Click on Launch Instance Button.
- Select View all Instances to View the Instance you Created
- Launch Status: Your instance is now launching. Click on the instance ID and wait for complete initialization of the instance (until the status changes to running).
Task 3: Create an Amazon RDS Database
- Navigate to Aurora and RDS under Database.
- Click on Create Database button
-
Specify DB Details:
-
Database creation method : Select Standard create

-
Database creation method : Select Standard create
- Engine options : Select MySQL
-
Version : Default

-
Templates : Select Sandbox

- DB instance identifier : Enter mydbinstance
- Master username : Enter rdsuser
- Master password and Confirm password: Enter whizlabs123
- Note: This is the username/password combo used to log onto your database. Please make note of them somewhere safe.
-
DB instance class : db.t3.micro — 1 vCPU, 1 GiB RAM

- Storage type : General Purpose SSD (gp2)
- Allocated storage : 20
-
Enable storage autoscaling : Uncheck

- Public access : Select No
- VPC Security groups : Select Choose existing
- Existing VPC security groups : Remove the default one and Select MyEC2Server_SG
-
Go to Additional Configuration options
- Initial database name: Enter mydbinstance
- DB parameter group: default
- Option group: default
- Enable automated backups: uncheck
- Log Exports: Not needed for the purpose of this lab.
- Note: Leave all the other settings as default
- Click on Create database
- Navigate to databases.
- On the RDS console, the details for the new DB instance appear. The DB instance has a status of creating until the DB instance is ready to use. When the state changes to Available, you can connect to the DB instance. It can take up to 20 minutes before the new instance status becomes Available.
- Once the database becomes Available, click on the database name and copy the Endpoint under Connectivity & security tab.
Task 4: Create a connection to the Amazon RDS database from the EC2 instance
In this task, we are going to establish a connection between the EC2 instance and the RDS database.- Now navigate to EC2 by clicking on the Services menu in the top, then click on the EC2 in the Compute section.
-
Navigate to Instances on the left panel and select your EC2 instance(MyPublicServer) and click on the Connect button.

-
Select EC2 Instance Connect option and click on Connect button.(Keep everything else as default)

-
A new tab will open in the browser where you can execute the CLI Commands.

-
Once connected to the server:
-
Switch to the root user using the command:
-
Switch to the root user using the command:
-
Connect to the MySQL RDS Instance with the following command:
- Syntax: mysql -h <mysql-instance-dns> -u <username> -p
- In our case: mysql -h mydbinstance.c1sh5a4j91dp.us-east-1.rds.amazonaws.com -u rdsuser -p
- Password : Enter whizlabs123
- You will enter the MYSQL command line.

Task 5: Create a Database, Table and insert data for testing
Lets create a simple database and table to see if it’s working.-
Create a database:
-
You can see the created database with following command:

-
Switch to the database named SchoolDB.
-
Create a sample table consisting of Subjects.
-
Insert some details into the table:
-
Let’s check the items we added into the table:

- Try out some more SQL commands and play around with the table to strengthen your understanding.
-
Run below command to exit the mysql command
Task 6: Validation Test
- Once the lab steps are completed, please click on the Check my work button on the left side panel.
- This will validate the resources in the AWS account and shows you whether you have completed this lab successfully or not.
- Sample output :

Task 7: Delete AWS Resources
7.1 Deleting EC2 Instance
- Navigate to EC2 by clicking on the Services menu in the top, then click on the EC2 in the Compute section.
-
All the EC2 Instances will be listed here,

-
To terminate the EC2, perform the following task:
- Select MyPublicServer,
- Click on Instance state (If you don’t see an Instance state option, click on the Actions button and then choose Instance state)
-
Select Terminate instance

-
Finally, Click on terminate

- EC2 Instance is terminated.
7.2 Deleting RDS DB Instance
- Navigate to RDS by clicking on the Services menu available under the Database section.
- Click on DB Instances
- It will list all the RDS databases
-
Click on Actions and select Delete

-
To delete, we have to perform several tasks:
- Uncheck the option of Create final snapshot,
- Acknowledge by selecting the second option,
- Type delete me to confirm
-
And finally, click on Delete button below.

- It will take around, 5 minutes to delete the instance, you can end the lab now.
Completion and conclusion
- You have successfully launched an EC2 Instance in a default VPC.
- You successfully ran a MySQL command and performed operations on a database created with Amazon RDS.
End lab
- Sign out of AWS Account.
- You have successfully completed the lab.
- Once you have completed the steps, click on End lab in the IP Lab Portal.
What gets checked
When you press Check my work, the platform verifies each of these:- Launch an EC2 Instance — Check whether an EC2 Instance is launched or not.
- Launch EC2 AMI type Amazon Linux — Check whether the EC2 instance is launched using an Amazon AMI.
- Launch RDS instance — Check whether an RDS Instance is created or not
- Check whether RDS database Engine type is mysql — Check whether allowed database type mysql is deployed or not