Today we’re going to learn how to set up auto scaling group with AWS’s Elastic Load Balancer, with third party DNS, like Cloudflare.

  1. Set up Launch Template or Launch Configuration

This is the template for all the instances that will be auto started and added to the auto scaling group.
If you don’t need additional settings, just need to start an instance with pre-defined AMI, then Launch configuation is good enough; but if you need to do additional steps, use Launch Template instead.

Launch Templates are under Instances tab, whereas Launch Configuation are under Auto Scalging. Both options require AMI, you can either use one of the presets, or create an image from existing EC2 instances.

Note that the default security group only allows port 22, so if you’re using it as servers that requires 80 and/or 443 port, please remember to add them.

  1. Set up Target Groups

Load Balancers and Auto Scaling group and tied together using Target Groups.
Click on Target Group under Load Balancing to create a new group.

  1. Set up Auto Scaling Group

Click on Auto Scaling Groups under Auto Scaling to create a new group.

Launch configuation: Choose the launch configuation you just created
Group size: how many instances to start with
Advanced Details:

  • Select “Receive traffic from one or more load balancers”

  • Leave “Classic Load Balancers” blank

  • Select the Target Group you just created in “Target Group”

In Configure Scaling Policies, select “Use scaling policies to adjust the capacity of this group” and set up the policy like “scale between x and y, when average CPU is more than 50”

Review and save

  1. Set up Load Balancer

Select Application Load Balancer.
Scheme: select “internet-facing”
Listener: add HTTPS (port 443) if needed

At the 4th step: configure routing, choose the same target group as the one you chose during step 3

At the last step, you don’t have to register any targets, auto scaling group will create instance to the minimun instance number automatically.

  1. Associate Load Balancer with DNS

Find the public DNS on Load Balancer’s details tab.
If you’re using AWS’s Route 53 DNS, create an A (Alias) record to your desired domain name. If you’re using third party DNS, such as Cloudflare, create a CNAME record instead.

  1. Test

Your done! Link to the domain name to see if it works.