Amazon Aurora

Hands-On

Demo

In this demo, we will:

  1. Create an Amazon Aurora MySQL-compatible database cluster
  2. Set up an EC2 instance with a simple web application
  3. Connect the web application to the Aurora database
  4. Test Aurora's high availability feature
  5. Explore Aurora Features
  6. Test the setup
  7. Clean up resources

Agenda

Demo Overview

Launch EC2 instance

aurora-demo-instance

Application and OS Images

Amazon Machine Image (AMI)

Instance type

Create key pair

aurora-demo-instance-key-pair

Key pair (login)

Network settings

Launch instance

Create Aurora database

Engine options

Engine version

Templates

aurora-demo-cluster
admin
admin123

Settings

Cluster storage configuration

Instance configuration

Availability & durability

Connectivity

DB subnet group

Availability Zone

Read replica write forwarding

myapp

Database Name

Backtracking

Wait 5-10 minutes for creation

Connect to EC2 Instance

sudo dnf update -y
sudo dnf install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd

EC2 Commands - 1 - Install Apache Server

sudo dnf install -y php php-mysqlnd

EC2 Commands - 2 - Install PHP

sudo systemctl restart httpd
sudo systemctl status httpd
php --version

EC2 Commands - 3 - Install MySQL Client

sudo dnf install -y mariadb105
mysql --version

EC2 Commands - 4 - Add Database Endpoint

export USERNAME=admin
export PASSWORD=admin123
export DATABASE=myapp
export SERVERNAME=
sudo tee /var/www/html/index.php > /dev/null << EOL
<?php
\$servername = "${SERVERNAME}";
\$username = "${USERNAME}";
\$password = "${PASSWORD}";
\$dbname = "${DATABASE}";

// Create connection
\$conn = new mysqli(\$servername, \$username, \$password, \$dbname);

// Check connection
if (\$conn->connect_error) {
    die("Connection failed: " . \$conn->connect_error);
}
echo "Connected successfully to Aurora database!";
\$conn->close();
?>
EOL

Create Sample PHP Page for Database Connection

sudo systemctl restart httpd
sudo tee /var/www/html/index.php > /dev/null << EOL
<?php
\$servername = "${SERVERNAME}";
\$username = "${USERNAME}";
\$password = "${PASSWORD}";
\$dbname = "${DATABASE}";

// Create connection
\$conn = new mysqli(\$servername, \$username, \$password, \$dbname);

// Check connection
if (\$conn->connect_error) {
    die("Connection failed: " . \$conn->connect_error);
}

// Create table if not exists
\$sql = "CREATE TABLE IF NOT EXISTS visits (
    id INT AUTO_INCREMENT PRIMARY KEY,
    visit_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)";
\$conn->query(\$sql);

// Insert new visit
\$sql = "INSERT INTO visits (visit_time) VALUES (NOW())";
\$conn->query(\$sql);

// Get visit count
\$sql = "SELECT COUNT(*) as count FROM visits";
\$result = \$conn->query(\$sql);
\$row = \$result->fetch_assoc();
\$count = \$row['count'];

echo "Connected successfully to Aurora database!<br>";
echo "This page has been visited {\$count} times.";

\$conn->close();
?>
EOL

PHP Page to Count Total Visits

sudo systemctl restart httpd

Restart Web Server

Test

Add Reader Instances

Add reader

Take a look at other options

Clean Up

Delete Aurora Demo Cluster Instance

delete me

Delete EC2 Instances

Terminate (delete) instance

Delete Key Pair

Delete Database

Delete aurora-demo-cluster cluster?

delete me

🙏

Thanks

for

Watching