Amazon Aurora with Terraform
Aurora is a proprietary technology from AWS (not open-sourced)
Postgres and MySQL are both supported as Aurora DB (that means your drivers will work as if Aurora was a Postgres or MySQL database)
Aurora is “AWS cloud-optimized” and claims 5x performance improvement over MySQL on RDS, over 3x the performance of Postgres on RDS
💡 Aurora storage automatically grows in increments of 10GB, up to 128 TB.
Aurora can have up to 15 replicas and the replication process is faster than MySQL (sub 10 ms replica lag)
Failover in Aurora is instantaneous. It’s HA (High Availability) native.
Aurora costs more than RDS (20% more) — but is more efficient
One Aurora Instance takes writes (master)
Automated failover for master in less than 30 seconds
Master + up to 15 Aurora Read Replicas serve reads
Support for Cross Region Replication
RDS Cluster
resource "aws_rds_cluster" "rds-cluster" {
engine = "aurora-mysql"
engine_version = "8.0.mysql_aurora.3.02.1"
database_name = "mydb"
master_username = "admin"
master_password = "adminadmin"
storage_type = "gp3"
db_cluster_instance_class = "db.t3.medium"
allocated_storage = 25
network_type = "IPV4"
vpc_security_group_ids = [aws_security_group.rds_sg.id]
deletion_protection = false
backup_retention_period = 7
enabled_cloudwatch_logs_exports = ["error", "audit", "general"]
storage_encrypted = true
}
Aurora Cluster Instance (Writer)
resource "aws_rds_cluster_instance" "aurora_mysql_writer" {
identifier = "aurora-cluster-instance-1"
cluster_identifier = aws_rds_cluster.rds-cluster.id
instance_class = "db.t3.medium" # Choose your instance class (e.g., memory-optimized)
engine = aws_rds_cluster.rds-cluster.engine
publicly_accessible = false
}
Additional Aurora Cluster Instance (Reader)
resource "aws_rds_cluster_instance" "aurora_mysql_reader" {
identifier = "aurora-cluster-instance-2"
cluster_identifier = aws_rds_cluster.rds-cluster.id
instance_class = "db.t3.medium"
engine = aws_rds_cluster.rds-cluster.engine
publicly_accessible = false
}
Security — Group
resource "aws_security_group" "rds_sg" {
name = "allow-mysql-access"
description = "Allow MySQL access"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Replace with your allowed IP range for security
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
If you found this guide helpful then do click on 👏 the button.
Follow for more Learning like this 😊
If there’s a specific topic you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!