Zurien Blog

In our previous AWS networking blog, we already created Elastic load balancer (ELB), now we want to automate the creation of Target instance using Auto Scaling Group (ASG).

Creating ASG has 2 phases. First, you need to create Launch Template where we define EC2 instance as well as Security Groups. The 2nd phase is where you create Auto Scaling Group as associate the the Launch Template you create. Below is the step by guide in creating both phases.

Creating Launch Template

  1. On the left pane, Click Lunch Templates under Instances
  2. On the main pane, click Create launch template
  3. Assign a launch template name and add description.
  4. Enable Provide guidance to help me set up a template that I can use with EC2 Auto Scaling
  5. Under Application and OS Image, click Browse more AMIs. This will take you to a page where you can select which image/OS that will be installed in your EC2 instances.
  6. Select radio button next to the 1st option Amazon Linux 2 AMI (HVM) – Kernel 5.10 for simplicity sake. Click Select
  7. Under Instance type, select t3.micro
  8. Under Key pair, select Don’t include in launch template
  9. Under Security Group, select the same Security Group you created or selected in your ELB (Refer to the ELB Blog Post).
  10. On the Advanced Settings, under IAM Instance Profile, select the existing Instance Profile.
  11. Under User data, add a custom shell script. This will run when the instance starts and the script installs the application required dependencies and launch the application.
  12. Finally, click Create launch template located on the buttom right of the page.
  13. Click View launch template to verify if template has been created.

Creating Auto Scaling Group (ASG)

  1. On the left page, click Auto Scaling Group under Auto Scaling
  2. Click Create Auto Scaling group located on the upper right of the page.
  3. Assign preferred Auto scaling group name.
  4. Select the Lauch template name you created from previous task.
  5. Verify if details matches such as AMI ID, Security Group, Instance type etc.
  6. Click Next, this will take you to the Network configuration page of your Auto Scaling Group.
  7. Select the correct VPC and Availability Zone (Refer to the ELB Blog Post) . Click Next
  8. Select Attach to an existing load balancer and select the target group name you created (Refer to the ELB Blog Post).
  9. Under Health checks, select ELB to inherit the health check settings of your ELB. Click Next.
  10. Under Group size, Enter value of 2 for Desired, 2 for Minimum Capacity and 4 for Maximum Capacity.
  11. Under Scaling Policies, Select Average CPU Utilization, Enter a value of 40 for Target Value. Click Next.
  12. We will now activate Notifications by clicking Add Notifications. Click Create Topic.
  13. Assign a topic name and make sure to add recipient email address as alarms/notifications will be sent to the email address you entered.
  14. Click Next, click Next as we will not be configuring Tags.
  15. Review Auto Scaling Group configuration and click Create Auto Scaling Group.

Click below to access the video version and consider subscribing.

Leave a Reply

Your email address will not be published. Required fields are marked *