In this lab I will work with RDS, use EC2 instance to run queries and Session Manager to connect.
- Systems Manager
In this lab I will create a RDS database in a DB Subnet Group. I will use an EC2 instance to run queries against the database. I will use Session Manager to start a session on an running EC2 instance.
- Create a DB Subnet Group
- Create a MySQL Database in RDS
- Run queries against database using Session Manager
- AWS account
- An EC2 Instance running
- In the RDS dashboard go to Subnet groups and create DB Subnet Group. Select all available AZ and subnets.
- Go to the VPC dashboard and then Security Groups and create a new security group. This secuiry group will allow acces to the database.
- Back in the RDS dashboard create a database. Choose MySQL Free tier template. Set up the name, user and password, choose db.t2.micro instance class, disable storage autoscaling. In the Connectivity section choose the Security Group created in previous step. In the Additional configuration give the db an Initial name, uncheck the automatic backups. Leave all the other fields as default.
- Navigate to Systems Manager and then to Session Manager and start a session. Choose the running EC2 Instance. When in shell session change the role by running:
sudo -i -u ec2-user
- Install the mysql client:
sudo yum -y install mysql
- Navigate to the RDS Databases view and copy the endpoint:
- In your session, run the following command replacing your.endpoint.aws.com with the endpoint you noted earlier:
mysql -h <<your.endpoint.aws.com>> -u cloudacademy -p rdsappdb
- Create a new table by executing this command:
CREATE TABLE laboratory ( id INT, name VARCHAR(100) );
- Verify that your table was created by executing this command:
- Close your database connection by executing this command:
- Back in the RDS Console click Databases and delete the earlier created database.