AWS High Availability with Auto Scaling

Betty Barrera
5 min readJun 6, 2021

--

This following process will be used to test our highly availability servers to make sure we have 0% downtime.

Create Launch Template

1. Navigate to EC2 and select Launch Template

2. Click on Create Launch Template

  • Launch template nameGive it the name you desire
  • Template version description — Give it the description you desire
  • Provide guidance to help me set up a template that I can use with EC2 Auto Scaling — Make sure to check the box
  • Amazon machine image (AMI) — Select Amazon Linux 2 AMI (HVM), SSD Volume Type
  • Instance Type — Select t2.micro (Free tier eligible)
  • Key Pair (login) — Create Key Pair give it the name you desire, click on Create Key Pair. Make sure not to lose the downloaded key pair as you will need it.
  • Network Settings —Only update Security Groups to default VPN
  • Storage (volumes) — Leave defaults
  • Resource Tags — Leave defaults
  • Network Interface — Leave defaults
  • Advance Details — Update User Data only, copy and paste the following bootstrap script to start the Apache Web Server.
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
  • Click on Create Launch Template

Create Auto Scaling Group

1. Navigate to EC2 and select Auto Scaling Groups

2. Click on Create Auto Scaling Group

  • Auto Scaling group nameGive it the name you desire
  • Launch template — Select launch template created from the drop down list
  • Click on Next, this will take you to Configure settings.
  • Instance purchase options — Adhere to launch template
  • Network — Select default VPN and select 3 Subnets from the drop down list
  • Click on Next, this will take you to Configure advanced options.
  • Configure Advance Options — Leave defaults
  • Click on Next, this will take you to Configure group size and scaling policies.
  • Group size — Desired capacity will be set at 2, Minimum capacity will be set at 2, and Maximum capacity will be set at 5.
  • Scaling policies and Instance scale-in protection — Leave defaults
  • Click on Next until you get to Review, we don’t need to make any changes for Notifications or Tags.
  • Click on Create Auto Scaling Group
  • Give it a few minutes and select the Auto Scaling Group created, then go to Activity. If you scroll down you will see Activity History where you will see the status of Successful to confirm launches of the instances.

Create CloudWatch Alarms

1. Navigate to CloudWatch Alarms, click on Alarms then click on Create Alarm.

  • Click on Select metric
  • Click on EC2
  • Click on By auto scaling group
  • Scroll until you see Auto Scaling Group Name you created then select CPUUtilization.
  • Click on Select Metric, this will take you to Specify metric and conditions.
  • Metric — Leave defaults
  • Conditions — Threshold will be static, Whenever CPUUtilization will be Greater/Equal and than will be set to 80
  • Click on Next, this will take you to Notifications.
  • Alarm state trigger — In Alarm
  • Select an SNS topic — Create new topic
  • Create a new topic — Give it the name you desire
  • Email endpoints that will receive the notification — Email address where messages will be sent
  • Click on Create Topic
  • Click on Next, this will take you to Add name and description.
  • Alarm Name — Give it the name you desire
  • Alarm Description — Give it the description you desire
  • Click on Next
  • Review and click on Create Alarm

3. Repeat all steps for our ScaleIn alarm with the following changes:

  • Conditions — Threshold will be static, Whenever CPUUtilization will be Lower/Equal and than will be set to 40
  • Create a new topic — Give it the name you desire
  • Alarm Name — Give it the name you desire
  • Alarm Description — Give it the description you desire

Add Scaling Policies

1. Navigate to Auto Scaling Group, select group created then go to Automatic Scaling.

2. Select Create dynamic scaling policy

  • Policy type — Step scaling
  • Scaling policy name — Give it the name you desire
  • CloudWatch alarm — Select the High CPU alarm created
  • Take the action — Select Add, 1 and capacity units
  • lick on Create

3. Repeat all steps, but remove capacity.

Testing Auto Scaling

We will now test Auto Scaling Group by stressing out.

1. Navigate to EC2 instances

2. Select one of the two instances created and click on connect to get information to SSH into the instance.

3. SSH into your instance

4. Run command “sudo amazon-linux-extras install epel -y” without the quotes.

5. Run command “sudo yum install stress -y” without the quotes to install the stress command.

6. Now we will run the stress command “stress --cpu 100” without the quotes you could cancel at anytime with CTRL + C.

7. Alarm was triggered in CloudWatch and new instance was launched to meet demand.

8. After a few minutes of completing stress test CPU dropped below 40%, alarm was generated and addition instance was terminated.

Clean Up

We have now successfully tested Auto Scaling and may remove everything we created since it is no longer needed.

1. Terminate the instance that are running and that are no longer needed.

2. Delete Auto Scaling group created.

3. Delete Launch Template created.

4. Remove CloudWatch alarms created.

--

--