Wednesday, May 7, 2025

Blue-Green Deployment for Amazon RDS databases

 

Step-by-Step: Blue-Green Deployment for Amazon RDS

🔹 Use Case

  • Safely upgrade schema/engine version.

  • Avoid downtime and rollback risks.

  • Test changes on an exact replica before promoting.


1. Create a Green (Clone) Environment

You have several options depending on your current setup:

Option A: Snapshot and Restore

  1. Take a snapshot of your current RDS (Blue).

  2. Restore a new DB instance from that snapshot (this becomes Green).

    aws rds create-db-instance \
    --db-instance-identifier green-db \ --db-snapshot-identifier snapshot-of-blue

Option B: Read Replica (for supported engines like MySQL/PostgreSQL)

  1. Create a read replica of Blue.

    aws rds create-db-instance-read-replica \
    --db-instance-identifier green-db \ --source-db-instance-identifier blue-db
  2. Promote it to a standalone DB instance (optional if testing writes).

    aws rds promote-read-replica \
    --db-instance-identifier green-db

2. Apply Changes to Green

  • Apply schema changes, engine upgrades, or parameter group updates to the Green database.

  • Use a test application or staging environment to connect to Green and validate functionality.


3. Validate Green

  • Run integration and regression tests.

  • Monitor performance, query plans, indexes, etc.

  • Verify replication (if using a read replica).

  • Ensure no application-breaking changes exist.


4. Redirect Application to Green

Once Green is validated:

Option A: Update the DB Endpoint

  • Update the application/database connection string to point to Green’s endpoint.

  • If you’re using Route 53, change the CNAME for the DB hostname.

Option B: Switchover using Route 53

  • Use a CNAME (e.g., db.myapp.com) pointing to the current RDS instance.

  • Change the CNAME to point to Green DB's endpoint.


5. Monitor Green

  • Use CloudWatch for RDS metrics (CPU, IOPS, connections).

  • Monitor application performance post-switch.

  • Optionally keep Blue as backup for rollback.


6. Decommission Blue (Optional)

  • After confirming stability, delete or snapshot the Blue instance.

    aws rds delete-db-instance \
    --db-instance-identifier blue-db \ --skip-final-snapshot # or provide --final-db-snapshot-identifier

🧠 Best Practices

  • Enable automated backups on both instances.

  • Use parameter groups for environment isolation.

  • Use CloudFormation or Terraform for reproducible infrastructure.