DEV Community

Zahraa Jawad
Zahraa Jawad

Posted on

Auto Scaling group and Launch Template configuration

The service : EC2 Auto Scaling

Purpose : Application scaling to optimize performance and costs

What is Amazon EC2 Auto Scaling?

Amazon EC2 Auto Scaling allows to add or remove Amazon EC2 instances automatically in response to a variable application request. By automatically resizing and ejecting versions as needed, you can maintain a greater sense of app availability.

Image description

Amazon EC2 Auto Scaling helps to maintain application availability and allows to automatically add or remove EC2 instances according to conditions you define. You can use the fleet management features of EC2 Auto Scaling to maintain the health and availability of your fleet. You can also use the dynamic and predictive scaling features of EC2 Auto Scaling to add or remove EC2 instances.
Dynamic scaling responds to changing demand and predictive scaling automatically schedules the right number of EC2 instances based on predicted demand. Dynamic scaling and predictive scaling can be used together to scale faster.

How Amazon EC2 Auto Scaling works

Fleet Management

Whether you are running one Amazon EC2 instance or thousands, you can use Amazon EC2 Auto Scaling to detect impaired Amazon EC2 instances and unhealthy applications, and replace the instances without your intervention. This ensures that your application is getting the compute capacity that you expect. Amazon EC2 Auto Scaling will perform three main functions to automate fleet management for EC2 instances:

• Monitor the health of running instances

Amazon EC2 Auto Scaling ensures that your application is able to receive traffic and that EC2 instances are working properly. Amazon EC2 Auto Scaling periodically performs health checks to identify any instances that are unhealthy.

• Replace impaired instances automatically

When an impaired instance fails a health check, Amazon EC2 Auto Scaling automatically terminates it and replaces it with a new one. That means that you don’t need to respond manually when an
instance needs replacing.

• Balance capacity across Availability Zones

Amazon EC2 Auto Scaling can automatically balance instances across zones, and always launches new instances so that they are balanced between zones as evenly as possible across your entire fleet.

Scheduled Scaling

Scaling based on a schedule allows you to scale your application ahead of known load changes. For example, every week the traffic to your web application starts to increase on Wednesday, remains high on Thursday, and starts to decrease on Friday. You can plan your scaling activities based on the known traffic patterns of your web application.

Image description

Dynamic Scaling

Amazon EC2 Auto Scaling enables you to follow the demand curve for your applications closely, reducing the need to manually provision Amazon EC2 capacity in advance. For example, you can use target tracking scaling policies to select a load metric for your application, such as CPU utilization. Or, you could set a target value using the new “Request Count Per Target” metric from Application Load Balancer, a load balancing option for the Elastic Load Balancing service. Amazon EC2 Auto Scaling will then automatically adjust the number of EC2 instances as needed to maintain your target.

Predictive Scaling

Predictive Scaling, now natively supported as an EC2 Auto Scaling policy, uses machine learning to schedule the right number of EC2 instances in anticipation of approaching traffic changes. Predictive Scaling predicts future traffic, including regularly-occurring spikes, and provisions the right number of EC2 instances in advance. Predictive Scaling’s machine learning algorithms detect changes in daily and weekly patterns, automatically adjusting their forecasts. This removes the need for manual adjustment of Auto Scaling parameters as cyclicality changes over time, making Auto Scaling simpler to configure. Auto Scaling enhanced with Predictive Scaling delivers faster, simpler, and more accurate capacity provisioning resulting in lower cost and more responsive applications.

Image description

launch template

A launch template is an Amazon Elastic Compute Cloud (EC2) feature that reduces the number of steps that are required to create an AWS instance by capturing all launch parameters within one resource.
Before we can create an Auto Scaling group using a launch template, we must create a launch template with the parameters required to launch an EC2 instance. These parameters include the ID of the Amazon Machine Image (AMI) and an instance type. A launch template provides full functionality for Amazon EC2 Auto Scaling and also newer features of Amazon EC2 such as the current generation of Amazon EBS Provisioned IOPS volumes (io2), EBS volume tagging, T2 Unlimited instances, Elastic Inference, and Dedicated Hosts.

The steps for creation Auto Scaling group

The Basic steps for adding the EC2 Auto Scaling.

Step 1: Create Auto scaling group
Step 2: Configure Launch Template

The steps for creation Auto Scaling group

  1. From https://console.aws.amazon.com/ec2/.
  2. Sign into the AWS Management Console.
  3. On the navigation pane, under Auto Scaling, choose Auto Scaling Group.
  4. Chose Create Auto scaling group

Image description

5. Add name to the auto scaling
6. Chose the launch template or create new one

Image description

Step 2: To create a launch template

  1. After choose Create launch template. Enter a name and provide a
    description for the initial version of the launch template.

  2. Under Auto Scaling guidance, select the check box to have Amazon
    EC2 provide guidance to help create a template to use with
    Amazon EC2 Auto Scaling.

Image description

3. Under Launch template contents, fill out each required field and any optional fields as needed.
Application and OS Images(Amazon Machine Image):(Required)

• Choose the ID of the AMI for your instances. You can search through all available AMIs, or select an AMI from the Recents or Currenlly in use.

Image description

• or chose Quick Start list. If you don't see the AMI that you need, choose Browse more AMIs to browse the full AMI catalog.
To choose a custom AMI, you must first create your AMI from a customized instance.

Image description

4. For Instance type, choose a single instance type that's
compatible with the AMI that you specified.

Image description

5. To launch an Auto Scaling group with multiple instance types, choose Advanced, Specify instance type attributes, and then specify the following options:

Image description

• Number of vCPUs: Enter the minimum and maximum number of vCPUs.
To indicate no limits, enter a minimum of 0, and keep the
maximum blank.

• Amount of memory (MiB): Enter the minimum and maximum amount of
memory, in MiB. To indicate no limits, enter a minimum of 0, and
keep the maximum blank.

• Expand Optional instance type attributes and choose Add attribute
to further limit the types of instances that can be used to
fulfill your desired capacity.

• Resulting instance types: You can view the instance types that
match the specified compute requirements, such as vCPUs, memory,
and storage

6. Key pair (login): For Key pair name, choose an existing key pair,

Image description

or choose Create new key pair to create a new one.

Image description

7. Network settings:

• For Subnet chose any subnet or Don’t include in launch template, or Create new subnet.
• For Firewall (security groups), use one or more security groups, or keep this blank and configure one or more security groups as part of the network interface.

Image description

Note: If you don't specify any security groups in your launch template, Amazon EC2 uses the default security group for the VPC that your Auto Scaling group will launch instances into. By default, this security group doesn't allow inbound traffic from external networks.

8. In Advanced network configuration

• Change the default network interface settings. For example, you can enable or disable the public IPv4 addressing feature, which overrides the auto-assign public IPv4 addresses setting on the
subnet.

Image description

Note: Skip this step to keep the default network interface settings.

9. Storage (volumes)

Modify the storage configuration.

Image description

Note: Skip this step to keep the default storage configuration.

10. Resource tags

specify tags by providing key and value combinations. If you specify instance tags in your launch template and then you choose to propagate your Auto Scaling group's tags to its instances, all the tags are merged. If the same tag key is specified for a tag in your launch template and a tag in your Auto Scaling group, then the tag value from the group takes precedence.

Image description

11. Configure advanced settings (Optional)

Image description

12. When all configurations are ready to create the launch template, choose Create launch template.

Image description

Successfully created template.

Image description

Return to the creation of Auto Scaling group and select the template that created:

Image description

Network Select the VPC and subnets you want to deploy instances in. For this blog, we will use default VPC and two subnets. You can select as many subnets as you want.

Image description

Instance type requirements

You can keep the same instance attributes or instance type from your launch template, or you can choose to override the launch template by specifying different instance attributes or manually adding instance types.

Image description

Instance purchase options

To run fault-tolerant workloads at low cost, define a percentage of instances that will be Spot Instances. Spot Instances are spare EC2 capacity that offer steep discounts compared to On-Demand prices that AWS can interrupt with a 2-minute notification.

Image description

On-Demand allocation strategy
Choose the allocation strategy to apply to your On-Demand Instances when they are launched.

Image description

Configure advanced options

Choose a load balancer to distribute incoming traffic for your application across instances to make it more reliable and easily scalable. You can also set options that give you more control over health check replacements and monitoring.

Image description

Health check-optional

EC2 Auto Scaling automatically replaces instances that fail health checks. If you enabled load balancing, you can enable ELB health checks in addition to the EC2 health checks that are always enabled.

Image description

Configuration of group size - optional

Auto scaling group size defines the maximum and the minimum number
of instances to be launched in an auto-scaling group and can also be used to maintain a constant number of instances on AWS. Enter the same number for Desired capacity, Minimum capacity, and Maximum capacity to maintain a constant number of instances in the auto-scaling group.

Image description

For this demo, enter the 2 instance as Desired capacity and 1 Minimum capacity and 3 instances as Maximum capacity.

Scaling policy - optional

Choose to use a scaling policy to dynamically resize your Auto Scaling group to meet changes in demand.

Image description

Configuration SNS topics to Send notifications when Amazon EC2 Auto Scaling launches or terminates the EC2 instances in your Auto Scaling group.

Image description

Tags

Can add tags to help searching, filter, and track your Auto Scaling group across AWS, and can also choose to automatically add these tags to instances when they are launched.

Image description

After the review all configuration select Create Auto Scaling group

Image description

Image description

Latest comments (0)