0
0
AWScloud~5 mins

Multi-AZ deployment for high availability in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes servers or data centers can fail. Multi-AZ deployment means running your app in multiple places at once to keep it working even if one place stops.
When you want your website to stay online even if one data center has a problem.
When you run a database and want it to keep working if one zone goes down.
When you want faster recovery from failures without manual fixes.
When you want to balance traffic across different locations for better speed.
When you want to meet rules that require your data to be safe and always available.
Config File - main.tf
main.tf
provider "aws" {
  region = "us-east-1"
}

resource "aws_db_instance" "example" {
  allocated_storage    = 20
  engine               = "mysql"
  engine_version       = "8.0"
  instance_class       = "db.t3.micro"
  name                 = "mydb"
  username             = "admin"
  password             = "StrongPass123!"
  multi_az             = true
  publicly_accessible  = false
  skip_final_snapshot  = true
}

This Terraform file creates a MySQL database instance in AWS.

The key part is multi_az = true, which tells AWS to deploy the database in two availability zones for high availability.

This means if one zone fails, the other keeps the database running.

Commands
This command sets up Terraform in the current folder and downloads the AWS provider plugin needed to create resources.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v4.60.0... - Installed hashicorp/aws v4.60.0 (signed by HashiCorp) Terraform has been successfully initialized!
This command shows what Terraform will create or change before actually doing it. It helps you check your setup.
Terminal
terraform plan
Expected OutputExpected
An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_db_instance.example will be created + resource "aws_db_instance" "example" { + allocated_storage = 20 + engine = "mysql" + engine_version = "8.0" + instance_class = "db.t3.micro" + multi_az = true + name = "mydb" + username = "admin" + publicly_accessible = false + skip_final_snapshot = true } Plan: 1 to add, 0 to change, 0 to destroy.
This command creates the database with Multi-AZ enabled. The flag skips asking for confirmation to speed up the process.
Terminal
terraform apply -auto-approve
Expected OutputExpected
aws_db_instance.example: Creating... aws_db_instance.example: Still creating... [10s elapsed] aws_db_instance.example: Creation complete after 1m30s [id=mydb] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
-auto-approve - Skip manual approval to apply changes immediately
This AWS CLI command checks the details of the created database to confirm Multi-AZ is enabled.
Terminal
aws rds describe-db-instances --db-instance-identifier mydb
Expected OutputExpected
{ "DBInstances": [ { "DBInstanceIdentifier": "mydb", "MultiAZ": true, "DBInstanceStatus": "available", "Engine": "mysql", "DBInstanceClass": "db.t3.micro" } ] }
--db-instance-identifier - Specify the exact database instance to describe
Key Concept

If you remember nothing else from this pattern, remember: Multi-AZ means running your app or database in two places at once to keep it working during failures.

Common Mistakes
Not setting multi_az = true in the database configuration
The database will run in only one zone and can fail if that zone goes down.
Always include multi_az = true to enable high availability.
Skipping verification after deployment
You might think Multi-AZ is enabled but it is not, risking downtime.
Use AWS CLI or console to confirm Multi-AZ is active after deployment.
Summary
Write a Terraform file with multi_az = true to create a highly available database.
Run terraform init, plan, and apply to deploy the database.
Verify the Multi-AZ setting using AWS CLI to ensure high availability.