iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Aurora

Aurora is AWSs cloud-native database engine — wire-compatible with Postgres or MySQL, but with a separate storage layer that gives you faster failover, replicas at < 10ms lag, point-in-time recovery, and serverless v2 (auto-scaling capacity units). Reach for it when RDS is not big or fast enough; reach back for RDS when Aurora is overkill.

Provision, connect, fail over, and tune

EXAMPLE
# 1) Create a subnet group (required) + security group
aws rds create-db-subnet-group \
  --db-subnet-group-name shop-aurora-subnets \
  --db-subnet-group-description 'private subnets for aurora' \
  --subnet-ids subnet-aaa subnet-bbb subnet-ccc

sg=$(aws ec2 create-security-group --group-name aurora-clients \
        --description '5432 from app tier' --vpc-id vpc-0abc1234 \
        --query 'GroupId' --output text)
aws ec2 authorize-security-group-ingress --group-id $sg \
  --protocol tcp --port 5432 --source-group sg-app-tier

# 2) Create the cluster (Aurora PostgreSQL)
aws rds create-db-cluster \
  --db-cluster-identifier shop-aurora-pg \
  --engine aurora-postgresql --engine-version 16.2 \
  --master-username postgres \
  --master-user-password "$(openssl rand -base64 32)" \
  --db-subnet-group-name shop-aurora-subnets \
  --vpc-security-group-ids $sg \
  --storage-encrypted \
  --backup-retention-period 14 \
  --preferred-backup-window '13:00-14:00' \
  --preferred-maintenance-window 'mon:14:30-15:30' \
  --tags Key=project,Value=shop

# 3) Add primary writer + one reader instance
aws rds create-db-instance \
  --db-instance-identifier shop-aurora-pg-1 \
  --db-instance-class db.r7g.large \
  --engine aurora-postgresql \
  --db-cluster-identifier shop-aurora-pg

aws rds create-db-instance \
  --db-instance-identifier shop-aurora-pg-2 \
  --db-instance-class db.r7g.large \
  --engine aurora-postgresql \
  --db-cluster-identifier shop-aurora-pg

# 4) Endpoints — read vs write
aws rds describe-db-cluster-endpoints --db-cluster-identifier shop-aurora-pg \
  --query 'DBClusterEndpoints[].{Type:EndpointType,Endpoint:Endpoint}'

# Use the cluster endpoint for WRITES
# Use the reader endpoint for READS (load-balanced across replicas)

# 5) Aurora Serverless v2 — scales capacity automatically
aws rds modify-db-cluster --db-cluster-identifier shop-aurora-pg \
  --serverless-v2-scaling-configuration MinCapacity=0.5,MaxCapacity=8

aws rds create-db-instance --db-instance-identifier shop-aurora-pg-sv2 \
  --db-instance-class db.serverless --engine aurora-postgresql \
  --db-cluster-identifier shop-aurora-pg
# 1 ACU ≈ 2 GB memory; billed per second.

# 6) IAM database authentication (no static passwords)
aws rds modify-db-cluster --db-cluster-identifier shop-aurora-pg \
  --enable-iam-database-authentication

# In Postgres
# psql -h <endpoint> -U app_user "sslmode=verify-full sslrootcert=/etc/ssl/rds-ca.pem" -d shop
# password = $(aws rds generate-db-auth-token --hostname <endpoint> --port 5432 --username app_user)
# 15-minute lifetime — fetch fresh per connection.

# 7) Failover testing
aws rds failover-db-cluster --db-cluster-identifier shop-aurora-pg
# Aurora promotes a replica; cluster endpoint switches in ~10 seconds.
# Reader endpoint requires a brief reconnection too.

# 8) Backups + PITR
# Automated backups: backup-retention-period above (1-35 days)
# Manual snapshot:
aws rds create-db-cluster-snapshot --db-cluster-identifier shop-aurora-pg \
  --db-cluster-snapshot-identifier shop-aurora-pre-migration-2026-06-18

# Restore to a point in time (within the retention window):
aws rds restore-db-cluster-to-point-in-time \
  --source-db-cluster-identifier shop-aurora-pg \
  --db-cluster-identifier shop-aurora-pg-recovery \
  --restore-to-time '2026-06-18T01:00:00Z'

# 9) Performance Insights
# Enable in console / CLI; dashboard shows top queries, waits, locks.
# Free for 7-day retention; longer is paid.

# 10) Monitoring + alerts
# - DBLoad / DBLoadCPU > 90% sustained -> scale up
# - ReplicaLag > 1s -> investigate workload
# - VolumeBytesUsed approaching limit -> Aurora autoscales storage (good)
# - StorageNetworkThroughput unusually high -> heavy scan; check indexes

# 11) When NOT to use Aurora
# - Tiny workloads -> RDS or Lightsail
# - Need engines other than Postgres/MySQL -> RDS (Oracle, SQL Server) or self-host
# - Bursty serverless workloads with idle time -> Aurora Serverless v2 with min=0.5 ACU OR Neon/PlanetScale
# - Cross-region active-active writes (Aurora Global is one writer + multiple readers)

Why it matters

Run Aurora behind two endpoints from day one: writes hit the cluster endpoint, reads hit the reader endpoint. Reads scale by adding readers (one CLI call), failovers complete in seconds, and your app picks up the new primary without changing any connection strings.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
# MySQL/Postgres-compatible cloud-native DB. Up to 5x faster than vanilla.
# Serverless v2 scales by load.
Try it Yourself »

Discussion

Loading…