AWS High Availability with Auto Scaling

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

  • 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

  • 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
  • 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

  • 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

Testing Auto Scaling

Clean Up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store