Skip to content

Aurora Database with EC2

Category Cloud & AWS Data & Serverless
Status โœ… Completed
Repo nextwork-aurora-database-with-ec2
Original NextWork guide nextwork.ai

Learning project

Practice work following a NextWork guide, separate from my production projects.

๐Ÿ“š NextWork learning project. This is a practice project I built while working through NextWork's Aurora Database with EC2 guide. It is part of my Learning portfolio and is fully separate from my production projects.

Category: Learning โ€บ Cloud & AWS Data & Serverless
Status: โœ… Completed

Overview

This creates a relational database (Amazon Aurora, MySQL-compatible) and connects to it from an EC2 instance using the mysql client. The guide's key security point is that the database's security group only accepts port 3306 from the EC2 instance's security group, never from the internet.

Summary

Created an Aurora MySQL 3 cluster (db.t3.medium writer) and an EC2 client on real AWS. From the instance I connected to the writer endpoint, created the EMPLOYEES table, and inserted and read rows. The database security group only admits 3306 from the EC2 security group. Everything was torn down with no final snapshot.

The checks behind this are in docs/verification.txt.

Skills & tools

AWS, Terraform, Infrastructure as Code, moto (AWS mock), Amazon Aurora, Amazon RDS, MySQL, Amazon EC2, Security groups, Docker, SQL

What I built

  • main.tf: Aurora MySQL cluster (database sample), a writer instance, an EC2 client, and two security groups chained 3306 โ† EC2 SG. The password comes from a sensitive variable and is never hard-coded.
  • mysql-connect-test.sh: real MySQL 8 'database' and client containers on an isolated network. It connects, creates EMPLOYEES, inserts rows, and reads them back.
  • checks.py: verifies the cluster, writer, and SG rule on the mock.

How to run

pip install -r requirements-dev.txt   # moto (local AWS mock) + boto3
./local-test.sh                       # terraform apply against the mock, run checks.py, then destroy

# Real AWS (costs money; use your own IAM user/profile):
terraform init && terraform apply      # mock_endpoint defaults to "" = real AWS
terraform destroy                      # clean up when done

Real MySQL connection test (Docker): ./mysql-connect-test.sh

Verification

I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.

PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh && ./mysql-connect-test.sh

Notes

  • The guide hard-codes the DB password in dbinfo.inc. Here it's a sensitive Terraform variable (local default only), and the local test generates a throwaway password. In production, use AWS Secrets Manager.

Real AWS deployment (2026-12-02)

I deployed this project to a real, dedicated AWS learning account (us-east-1, kept separate from everything else I run), checked it, captured the output, and tore it all down right after. Every resource carried the tag Project=nextwork-aurora-database-with-ec2 so I could prove nothing was left behind.

How I ran it: ./real-aws-run.sh (in this repo) does terraform init/apply with my AWS profile, runs checks.py against the real account, runs real-extra.sh for the live tests, and then always runs terraform destroy, even if a step fails. To get onto the instances I used EC2 Instance Connect with a throwaway SSH key that is only valid for 60 seconds. No key pairs were created in AWS and no keys were saved. The master password was random for each run, passed to Terraform as an environment variable, piped to the instance over SSH stdin, and never printed or committed.

Evidence (excerpt; the full, sanitized transcript is in docs/aws-real-run.txt, with the account ID redacted):

$ python3 checks.py   (against the real account)
ALL 3 CHECKS PASSED
$ ./real-extra.sh
--- Aurora cluster
aurora-mysql    8.0.mysql_aurora.3.10.3 available   nextwork-aurora.cluster-c8bsm2aio8m7.us-east-1.rds.amazonaws.com
db.t3.medium    available   False
mysql  Ver 15.1 Distrib 10.5.29-MariaDB, for Linux (x86_64) using  EditLine wrapper
--- from EC2: connect to nextwork-aurora.cluster-c8bsm2aio8m7.us-east-1.rds.amazonaws.com, create the table, insert + read rows
+----------------------+
| aurora_mysql_version |
+----------------------+
| 8.0.42               |
+----------------------+
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sample             |
| sys                |
+--------------------+
+----+--------------+-----------+
| ID | NAME         | ADDRESS   |
+----+--------------+-----------+
|  1 | Ada Lovelace | London    |
|  2 | Grace Hopper | Arlington |
+----+--------------+-----------+

Teardown

Resources were up from 20:18 to 20:31 CST on 2026-12-02, then destroyed and verified gone:

=== TEARDOWN 2026-12-02 20:24 CST ===
$ terraform destroy -auto-approve -input=false -no-color -var ami_id=ami-000d209a4fc9822c4 -var project_tag=nextwork-aurora-database-with-ec2
Destroy complete! Resources: 5 destroyed.
$ terraform state list   (should be empty)
$ aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=nextwork-aurora-database-with-ec2
$ live EC2 instances / volumes / VPCs tagged Project=nextwork-aurora-database-with-ec2 (should be empty)
=== teardown verified 20:31 CST ===
$ aws rds describe-db-clusters / describe-db-instances  (after teardown: no output = nothing left)

Cost

Estimated cost of the real run: about $0.03 (db.t3.medium Aurora writer for about 13 minutes plus a t2.micro). The account has a $50/month budget with email alerts at $5, $20 and $40, and the whole AWS series is logged in a private spend ledger.


Original project: https://nextwork.ai/projects/cee72c3a-f285-55a6-8217-3cee4023a3bf ยท Part of my NextWork Learning portfolio (hub).

Verification output

From docs/verification.txt:

$ PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh && ./mysql-connect-test.sh

Success! The configuration is valid.

Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
cluster_id = "nextwork-aurora"
db_sg = "sg-90a1ed8d7097ac629"
ec2_sg = "sg-94eda788e27288b01"
writer_endpoint = "nextwork-aurora.cluster-mc83rcn5am9g.us-east-1.rds.amazonaws.com"
PASS: Aurora MySQL cluster created
PASS: cluster has a writer instance
PASS: DB SG admits 3306 only from the EC2 SG
ALL 3 CHECKS PASSED
From the 'EC2' client container:
mysql_version
8.0.46
Database
information_schema
performance_schema
sample
ID  NAME    ADDRESS
1   Ada Lovelace    London
2   Grace Hopper    Arlington
PASS: connected over the network, created table, inserted + read 2 rows
Unable to find image 'mysql:8.0' locally
8.0: Pulling from library/mysql
edf85873f64e: Pulling fs layer
6ef6c7b50a93: Pulling fs layer
e3e5d1ac74c1: Pulling fs layer
0d74d296605b: Pulling fs layer
297d04cfe470: Pulling fs layer
4c8a3e0d4e4b: Pulling fs layer
a63160a5eda1: Pulling fs layer
0d74d296605b: Waiting
7534d1db9f8d: Pulling fs layer
297d04cfe470: Waiting
4c8a3e0d4e4b: Waiting
a63160a5eda1: Waiting
49ec2dab01d9: Pulling fs layer
7534d1db9f8d: Waiting
49ec2dab01d9: Waiting
ab24264a27e9: Pulling fs layer
96d30d9fbee8: Pulling fs layer
ab24264a27e9: Waiting
96d30d9fbee8: Waiting
6ef6c7b50a93: Verifying Checksum
6ef6c7b50a93: Download complete
e3e5d1ac74c1: Verifying Checksum
e3e5d1ac74c1: Download complete
297d04cfe470: Verifying Checksum
297d04cfe470: Download complete
0d74d296605b: Verifying Checksum
0d74d296605b: Download complete
4c8a3e0d4e4b: Download complete
7534d1db9f8d: Download complete
edf85873f64e: Download complete
ab24264a27e9: Verifying Checksum
ab24264a27e9: Download complete
96d30d9fbee8: Verifying Checksum
96d30d9fbee8: Download complete
a63160a5eda1: Verifying Checksum
a63160a5eda1: Download complete
49ec2dab01d9: Download complete
edf85873f64e: Pull complete
6ef6c7b50a93: Pull complete
e3e5d1ac74c1: Pull complete
0d74d296605b: Pull complete
297d04cfe470: Pull complete
4c8a3e0d4e4b: Pull complete
a63160a5eda1: Pull complete
7534d1db9f8d: Pull complete
49ec2dab01d9: Pull complete
ab24264a27e9: Pull complete
96d30d9fbee8: Pull complete
Digest: sha256:7dcddc01f13bab2f15cde676d44d01f61fc9f99fe7785e86196dfc07d358ae2b
Status: Downloaded newer image for mysql:8.0

[exit code 0]