Setup RDS Database

Now we're going to actually use RDS by setting up a quick facts database.

Make sure you're logged into the RDS database instance as the admin user using any MySQL client. Use the admin password from Secrets Manager.

step 1:

Paste in the following SQL to setup a new database with some data.

CREATE DATABASE random_facts_db;
USE random_facts_db;
CREATE TABLE facts (
id INT AUTO_INCREMENT PRIMARY KEY,
fact TEXT NOT NULL
);
INSERT INTO facts (fact) VALUES
('Wombat poo is cube-shaped.'),
('Bananas are berries, but strawberries aren''t.'),
('A flock of crows is known as a "murder".'),
('Honey never spoils; archaeologists have found pots of honey in ancient Egyptian tombs that are over 3,000 years old and still perfectly edible.'),
('Octopuses have three hearts and blue blood.'),
('Sloths can hold their breath longer than dolphins can.'),
('A group of flamingos is called a "flamboyance".'),
('A snail can sleep for three years at a time.'),
('The inventor of the frisbee was turned into a frisbee after he died.'),
('You are more likely to be bitten by a human than by a shark.');
step 2:

Paste in the following SQL to setup a new user to access the database.

CREATE USER 'mysql_user'@'%' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
GRANT SELECT, INSERT, UPDATE ON random_facts_db.* TO 'mysql_user'@'%';

We have just created a new user that will be able to connect to the database, but only by using IAM credentials. That means we don't need to worry about managing and rotating passwords for the database.

In order to connect to the database using this user we use IAM to generate a temporary password. We can do this right now using the AWS CLI, but we'll usually write code to do this from our application.

Cloud Course
Cloud Course
$89.70
$299.00 Lifetime
  • 81+ learning resources
  • 57 lessons and tutorials
  • 15 hands-on deployments
  • 9 quizzes
  • 29 videos (4h 17m 38s)
  • More content coming soon
  • Unlimited lifetime access to all course content
  • Deployment assessment CLI tool
  • Exclusive Discord access
Original Price:$299.00
Discount:-$209.30
Total:$89.70