You are on page 1of 27

AWS Solutions Architect Professional Week-2

Topics to be covered:
Week Broader Topics Tools to be
Topic covered

1. Introduction to Amazon EC2 Auto


Scaling
1.1 Auto Scaling components
1.2 Amazon EC2 Auto Scaling Benefits
AWS 1.3 Real-time case studies on Amazon
2 Compute EC2 Autoscaling Amazon
Service 2. Amazon EC2 Auto Scaling instance EC2-
lifecycle Autoscaling
2.1 Scale-Out
2.2 Scale-In
3. Quotas for Amazon EC2 Auto Scaling
4. Launch Templates
4.1 Create a launch template for an
Auto Scaling group
4.2 Copy launch configurations to
launch templates
4.3 Replace a launch configuration
with a launch template
5. Auto Scaling groups
5.1 Scale the size of your Auto Scaling
group
5.1.1 Scaling options
5.2 Set capacity limits on your Auto
Scaling group
6. Monitor your Auto Scaling instances
and groups
7. Lab Get started with Amazon EC2 Auto
Scaling
8.Case Study: AWS EC2 Autoscaling for E-
Commerce Application

1
AWS Solutions Architect Professional Week-2

1. Introduction to Amazon EC2 Auto Scaling


Amazon EC2 Autoscaling is a service provided by Amazon Web Services (AWS) that allows
users to automatically adjust the number of Amazon Elastic Compute Cloud (EC2) instances
running in a particular application or service based on the current demand.
The EC2 Autoscaling service allows users to define minimum and maximum numbers of EC2
instances to run at any given time. The service continuously monitors the application's
demand and adjusts the number of instances running based on predefined rules or policies.
This can be done based on various metrics such as CPU utilization, network traffic, and other
custom metrics.

When the demand for an application increases, the autoscaling service can add more
instances to handle the increased traffic, and when the demand decreases, it can reduce the
number of instances running to save costs.
EC2 Autoscaling can be used for various use cases such as handling sudden spikes in traffic,
improving application availability, and reducing infrastructure costs. It is a powerful tool that
can help automate the process of scaling applications and services, freeing up time for
developers and allowing them to focus on building great applications.

1.1 Auto Scaling components:


Amazon EC2 Auto Scaling is a service provided by Amazon Web Services (AWS) that enables
you to automatically scale your Amazon Elastic Compute Cloud (EC2) instances based on
demand. The following are the components of Amazon EC2 Auto Scaling:
1. Auto Scaling Group (ASG): An Auto Scaling group is a logical group of EC2 instances
that are launched from a common AMI (Amazon Machine Image) and configured
with the same settings. An ASG ensures that the desired number of EC2 instances are
running to handle the workload.

2
AWS Solutions Architect Professional Week-2

2. Launch Configuration: A launch configuration is a blueprint for creating new EC2


instances in an Auto Scaling group. It defines the AMI, instance type, security groups,
and other settings that are used to launch EC2 instances.
3. Scaling Policies: Scaling policies define the rules that determine when and how to
scale the EC2 instances in an ASG. You can define scaling policies based on metrics
such as CPU utilization or network traffic.
4. CloudWatch Alarms: CloudWatch alarms are used to monitor the metrics that are
used to trigger scaling events. You can create alarms based on metrics such as CPU
utilization or network traffic, and then associate those alarms with scaling policies.
5. Health Checks: Health checks are used to ensure that the EC2 instances in an ASG
are healthy and functioning properly. You can configure health checks to monitor
things like CPU utilization or response time.
6. Load Balancers: Load balancers are used to distribute traffic across multiple EC2
instances in an ASG. You can use a load balancer to ensure that traffic is evenly
distributed across instances and to help prevent instances from being overloaded.
7. Amazon EC2 instances: The actual EC2 instances that run your applications and
handle your workload are a critical component of Amazon EC2 Auto Scaling. The
number of instances is scaled up or down based on the rules defined in your Auto
Scaling policies.

1.2 Amazon EC2 Auto Scaling Benefits


Amazon EC2 Auto Scaling is a service provided by Amazon Web Services (AWS) that allows
users to automatically scale their Amazon Elastic Compute Cloud (EC2) instances up or down
based on changing demands. Some of the benefits of using Amazon EC2 Auto Scaling
include:
1. Increased availability: EC2 Auto Scaling allows users to set up multiple instances of
their application or website, ensuring that if one instance fails, there are others
available to take its place.
2. Cost optimization: With EC2 Auto Scaling, users can scale their instances based on
demand, only paying for the resources they need at any given time. This helps to
minimize costs and prevent over-provisioning.
3. Improved performance: By automatically adjusting the number of instances in
response to changing demands, EC2 Auto Scaling can help ensure that applications
and websites are able to handle fluctuations in traffic and workload, maintaining
performance and responsiveness.
4. Flexibility: EC2 Auto Scaling allows users to define policies for scaling up or down
based on a variety of criteria, such as CPU utilization, network traffic, or custom
metrics. This flexibility allows users to tailor their scaling strategy to their specific
needs and requirements.
5. Simplified management: EC2 Auto Scaling integrates with other AWS services, such
as Elastic Load Balancing and CloudWatch, to provide a comprehensive solution for
managing and scaling instances. This can help reduce the complexity of managing a
large number of instances manually.

3
AWS Solutions Architect Professional Week-2

Overall, Amazon EC2 Auto Scaling provides a powerful and flexible solution for scaling and
managing instances in the cloud, helping to improve availability, optimize costs, and
maintain performance and responsiveness.

1.3 Real-time case studies on Amazon EC2 Autoscaling:


Here are some real-time case studies on Amazon EC2 Autoscaling:

● Netflix: Netflix uses Amazon EC2 Autoscaling to handle the huge volume of traffic it
receives during peak hours. The company has a highly dynamic infrastructure that
requires automatic scaling of instances to maintain the user experience. By using
Amazon EC2 Autoscaling, Netflix is able to automatically increase the number of
instances during peak hours and decrease the number of instances during off-peak
hours.
● Yelp: Yelp uses Amazon EC2 Autoscaling to handle the large volume of traffic it
receives during peak hours. Yelp's infrastructure is highly dynamic and requires
automatic scaling of instances to maintain the user experience. By using Amazon EC2
Autoscaling, Yelp is able to automatically increase the number of instances during
peak hours and decrease the number of instances during off-peak hours.
● NASA: NASA uses Amazon EC2 Autoscaling to manage its computational workloads.
The agency uses Amazon EC2 Autoscaling to automatically scale its infrastructure to
meet the needs of its researchers and scientists. By using Amazon EC2 Autoscaling,
NASA is able to manage its computing resources efficiently and cost-effectively.
● SmugMug: SmugMug is a photo-sharing website that uses Amazon EC2 Autoscaling
to handle the high volume of traffic it receives during peak hours. The website's
infrastructure is highly dynamic and requires automatic scaling of instances to
maintain the user experience. By using Amazon EC2 Autoscaling, SmugMug is able to
automatically increase the number of instances during peak hours and decrease the
number of instances during off-peak hours.
● Zynga: Zynga is a social gaming company that uses Amazon EC2 Autoscaling to
handle the high volume of traffic it receives during peak hours. The company's
infrastructure is highly dynamic and requires automatic scaling of instances to
maintain the user experience. By using Amazon EC2 Autoscaling, Zynga is able to
automatically increase the number of instances during peak hours and decrease the
number of instances during off-peak hours.

2. Amazon EC2 Auto Scaling instance lifecycle

4
AWS Solutions Architect Professional Week-2

Amazon EC2 Auto Scaling provides a way to automatically scale the number of EC2 instances
in a group based on certain conditions. The instance lifecycle in Amazon EC2 Auto Scaling
consists of the following stages:

● Launch: When an EC2 Auto Scaling group needs to increase its capacity, it launches
new EC2 instances based on a specified launch configuration. The launch
configuration includes information such as the AMI (Amazon Machine Image) to use,
the instance type, and any other configuration details necessary to create the
instance.
● InService: Once an EC2 instance has been launched, it enters the InService state,
which means it is ready to handle requests. EC2 Auto Scaling monitors the health of
the instances in the group and can replace any instances that fail health checks.
● Terminate: When an EC2 Auto Scaling group needs to decrease its capacity, it
terminates instances that are no longer needed. The instances are terminated in a
way that ensures that any in-flight requests are completed before the instance is
shut down.
● Standby: EC2 instances can also be put into a Standby state, which means they are
still running but are not actively handling requests. This can be useful if you want to
temporarily reduce capacity but keep instances available for quick scaling if needed.
● Draining: When an EC2 instance is marked for termination, it enters a Draining state.
During this time, the instance stops receiving new requests, but it continues to
process any in-flight requests until they are completed or a specified timeout period
expires.
● Terminated: Finally, when an EC2 instance is no longer needed, it is terminated and
removed from the Auto Scaling group.

Overall, the instance lifecycle in Amazon EC2 Auto Scaling is designed to ensure that your
application has the capacity it needs to handle traffic, while also allowing you to manage
costs by only running the necessary number of instances at any given time.

2.1 Scale-Out:
Scale-out in Amazon EC2 autoscaling refers to the process of automatically adding more
instances to a group of EC2 instances based on a predefined scaling policy. The scaling policy
can be based on various parameters such as CPU utilization, network traffic, or other
metrics that indicate the need for additional resources.
When the scaling policy is triggered, Amazon EC2 autoscaling automatically launches new
EC2 instances to handle the increased workload, allowing the application to scale out and

5
AWS Solutions Architect Professional Week-2

handle increased traffic or demand. This process ensures that the application can continue
to provide a high level of performance and availability even during peak usage periods.
Once the workload decreases, Amazon EC2 autoscaling can also automatically terminate the
additional instances to save on costs and resources. Scale-out in Amazon EC2 autoscaling is
a key feature that enables applications to automatically respond to changes in demand and
maintain high levels of performance and availability.
The process for registering an instance with a load balancer for a scale-out event is outlined
in the sections that follow:

2.2 Scale-In:
Amazon EC2 Auto Scaling is a service that automatically adjusts the number of Amazon
Elastic Compute Cloud (EC2) instances in an Auto Scaling group according to changes in
demand for your application. The "scale" in EC2 Auto Scaling refers to the ability to increase
or decrease the number of instances running in response to changes in traffic or application
load.
The scaling process in Amazon EC2 Auto Scaling is based on a set of predefined rules called
"scaling policies". These policies are defined by the user and specify when to add or remove
instances from the Auto Scaling group. The rules can be based on different metrics, such as
CPU utilization, network traffic, or custom metrics that are specific to your application.
The scaling process can be done manually or automatically, depending on the configuration
of the Auto Scaling group. Manual scaling involves adding or removing instances manually,
while automatic scaling uses predefined rules to automatically adjust the number of
instances based on the current load.
The scale-in process in Amazon EC2 Auto Scaling involves several steps, including:

● Monitoring: The Auto Scaling group monitors the metrics defined in the scaling
policies, such as CPU utilization, network traffic, or custom metrics.

6
AWS Solutions Architect Professional Week-2

● Evaluation: The Auto Scaling group evaluates the metrics against the scaling policies
to determine whether to add or remove instances.
● Adjustment: If the evaluation indicates that instances need to be added or removed,
the Auto Scaling group adjusts the number of instances based on the scaling policies.
● Provisioning: If new instances need to be added, the Auto Scaling group provisions
new EC2 instances to the group based on the launch configuration.
● Termination: If instances need to be removed, the Auto Scaling group terminates the
instances based on the termination policy.
The scale-in process in Amazon EC2 Auto Scaling is designed to be seamless and transparent
to the end user, allowing for dynamic scaling of resources in response to changes in demand
for your application.

3. Quotas for Amazon EC2 Auto Scaling


Amazon EC2 Auto Scaling allows you to set quotas or limits on various resources to control
your usage and prevent unexpected charges. Here are some of the quotas that you can set
for Amazon EC2 Auto Scaling:
Auto Scaling groups per region: You can have up to 500 Auto Scaling groups per region.
Launch configurations per region: You can have up to 200 launch configurations per region.
The maximum number of instances: You can launch up to 1,000 instances per Auto Scaling
group.
Launch templates per region: You can create up to 200 launch templates per region.
Scaling policies per Auto Scaling group: You can create up to 50 scaling policies per Auto
Scaling group.

7
AWS Solutions Architect Professional Week-2

Target tracking scaling policies per Auto Scaling group: You can create up to 5 target
tracking scaling policies per Auto Scaling group.
Scheduled actions per Auto Scaling group: You can create up to 125 scheduled actions per
Auto Scaling group.

Note that these quotes may vary based on your account type and AWS region, so it's always
best to check the official documentation to get the most up-to-date information.

4. Launch Templates:
An Amazon EC2 Auto Scaling launch template is a customizable configuration that defines
various parameters for launching EC2 instances in an Auto Scaling group. The launch
template essentially acts as a blueprint for the instances that will be launched when scaling
out a group.
Some of the parameters that can be defined in a launch template include the Amazon
Machine Image (AMI) ID, instance type, key pair for SSH access, security groups, block
device mappings, and network interfaces.
Using launch templates in EC2 Auto Scaling can help simplify and streamline the process of
launching instances by providing a consistent configuration that can be easily updated and
managed. This can help ensure that instances launched in an Auto Scaling group are always
up-to-date with the latest software and security patches. Additionally, launch templates can
be used across multiple Auto Scaling groups, which can help reduce the amount of time and
effort required to manage multiple groups.

4.1 Create a launch template for an Auto Scaling group:


The procedures for configuring your launch template are as follows:

● The Amazon Machine Image (AMI) from which to deploy the instances must be
specified.
● Select an instance type that works with the AMI you've specified.

● When connecting to instances, for example through SSH, provide the key pair to use.

● To provide the instances access to the network, add one or more security groups.

● Tell each instance whether or not to add more volumes.

● The instances and volumes should be given unique tags (key-value pairs).

To create a Launch template:

8
AWS Solutions Architect Professional Week-2

1. Select Launch Templates from the Instances menu on the navigation pane.
2. To create a launch template, select it. Give the launch template's initial iteration a
name and a description.
3. Check the box next to "Auto Scaling guidance" to have Amazon EC2 offer instructions
on how to develop a template for use with Amazon EC2 Auto Scaling.
4. Fill out all mandatory fields as well as any optional options under Launch template
contents.
(a) (Required) Application and OS Images (Amazon Machine Image) Select the
AMI ID that corresponds to your instances. You may either choose an AMI
from the Recent or Quick Start list, or you can search through all of the
available AMIs. If the AMI you want is not shown, choose Browse More AMIs
to view the whole AMI catalog.
You must first make your AMI from a customized instance before you can
select a custom AMI. See Create an AMI in the Amazon EC2 User Guide for
Linux Instances for further details.
(b) Select just one instance type that works with the AMI you chose under the
Instance type.
Alternately, choose Advanced, specify instance type characteristics, and then
enter the following information to establish an Auto Scaling group with
various instance types:

● Enter the minimum and a maximum number of virtual CPUs. No


limitations are indicated by entering a minimum of 0 and leaving the
maximum field empty.
● Memory size (MiB): Indicate the minimum and maximum amounts of
memory. No limitations are indicated by entering a minimum of 0 and
leaving the maximum field empty.
● To further restrict the sorts of instances that can be utilized to reach
your target capacity, expand Optional instance type attributes and
choose to Add attribute.
● The instance types that fulfill the provided compute requirements,
such as vCPUs, RAM, and storage.
● Select Add an attribute to exclude certain instance types. Select
Excluded instance types from the Attribute list. Choose the instance
types you want to ignore from the Attribute value list.
(c) Key pair (login): Select an existing key pair for the Key pair name field, or
select Create new key pair to start a brand-new key pair. See Amazon EC2 key
pairs and Linux instances in the Amazon EC2 User Guide for Linux Instances
for further details.

9
AWS Solutions Architect Professional Week-2

(d) Network settings: Select one or more security groups for the firewall
(firewall), leave this field empty, or set up one or more security groups as
part of the network interface. See Amazon EC2 security groups for Linux
instances in the Amazon EC2 User Guide for Linux Instances for further
details.
(e) Modify the network interface's default configurations. For instance, you
may override the subnet's configuration that automatically assigns public
IPv4 addresses by enabling or disabling the public IPv4 addressing capability.
To maintain the network interface's default settings, skip this step.

(f) Change the setup of the storage. To maintain the default storage setup,
skip this step.
(g) Give key-value pairs for the tags you want to apply to resources. Instance
tags are merged if you define instance tags in your launch template and
subsequently decide to propagate your Auto Scaling group's tags to its
instances. The tag value from the Auto Scaling group will take priority if the
same tag key is given for a tag in your launch template and a tag in your Auto
Scaling group.
5. Select Create launch template when you're ready to start creating the launch
template.
6. Select Create Auto Scaling group from the confirmation screen to start the creation
of an Auto Scaling group.

4.2 Copy launch configurations to launch templates:


You must replicate or rebuild your launch settings as launch templates in order to convert
your current Auto Scaling groups from launch configurations to launch templates. This
subject demonstrates how to use the Amazon EC2 Auto Scaling interface to replicate your
launch configurations to launch templates. Only through the console is it possible to use the
copying capability.
To copy a launch configuration to a launch template
1. Open the Amazon EC2 console
2. Select Launch Configurations from the Auto Scaling drop-down menu on the
navigation pane.
3. Choose Copy to launch template, Copy chosen after selecting the launch
configuration you wish to duplicate. This creates a brand-new launch template with
the exact same settings and name as the launch configuration you choose.
4. You can add a new name or use the name of the launch configuration (the default)
for the new launch template name. Names for launch templates must be original.
5. Select Establish an Auto Scaling group using the new template (optional) to establish
a group utilizing auto-scaling with the updated launch template.
6. Select Copy.

10
AWS Solutions Architect Professional Week-2

Following launch settings should be copied to launch templates


1. Open the Amazon EC2 console
2. Select Launch Configurations from the Auto Scaling drop-down menu on the
navigation pane.
3. Select Copy all, copy to launch template. This creates a new launch template with
the same name and settings as the current Region's launch configurations.
4. Select Copy

4.3 Replace a launch configuration with a launch template:


You may define a launch template for an Auto Scaling group when editing it to replace a
launch configuration.
Any new instances are launched using the new launch template when the launch settings
have been changed. Instances that already exist are unaffected. You have two options for
updating the current instances: either you may terminate them or you can let automated
scaling progressively replace the current instances with new ones in accordance with the
group's termination policy. As soon as you terminate an instance, Amazon EC2 Auto Scaling
quickly starts deploying new instances to take its place.

Changing the launch settings for a console Auto Scaling group


1. Open the Amazon EC2 console
2. Next to your Auto Scaling group, tick the box.
3. The bottom of the page splits open to provide details about the selected group in
a new window.
4. Select Edit for Launch configuration under the Details tab.
5. Select Change to Launch template.
6. Choose your launch template under Launch template.
7. If necessary, choose the launch template version under Version. You may decide
whether the Auto Scaling group scales out using the default launch template or
the most recent version after creating variations of a launch template.
8. Select Update once you're done.

5. Auto Scaling groups


Amazon EC2 Autoscaling groups are a feature of Amazon Web Services (AWS) that
enable automatic scaling of EC2 instances based on demand.

An Autoscaling group allows you to define a minimum and maximum number of EC2
instances that should be running at all times to handle the load on your application.
When the demand for your application increases, the Autoscaling group
automatically launches new EC2 instances to handle the additional load. Conversely,

11
AWS Solutions Architect Professional Week-2

when the demand decreases, the Autoscaling group automatically terminates EC2
instances to reduce costs.

Autoscaling groups are particularly useful for applications with varying levels of
demand, such as those that experience spikes in traffic during specific times of the
day or during seasonal periods. By automatically adjusting the number of EC2
instances running, Autoscaling groups can help ensure that your application can
handle increased traffic while minimizing costs during periods of low demand.

To use Autoscaling groups, you need to create a launch configuration that defines
the EC2 instance type and other configuration options. You also need to set up a
scaling policy that determines when to add or remove instances from the group
based on metrics such as CPU utilization or network traffic.

Overall, Autoscaling groups can help you achieve better application availability,
improve performance, and reduce costs by automatically adjusting the number of
EC2 instances running based on demand.

There are differences between Spot Instances and On-Demand Instances:

Spot Instances and On-Demand Instances are both types of EC2 (Elastic Compute
Cloud) instances provided by Amazon Web Services (AWS) that differ in pricing and
availability.
The most popular sort of instance is one called On-Demand Instances, which lets you
pay for compute capability by the hour or second without making any upfront
payments or long-term obligations. For applications with erratic or transient
workloads, this pricing strategy is perfect.

Spot Instances, on the other hand, are available at a much lower price than On-
Demand Instances but are subject to variable pricing and availability. Spot Instances
are ideal for applications that have flexible start and end times or that can withstand
interruptions, such as batch processing jobs, data analysis, and testing.

The price of Spot Instances can fluctuate based on supply and demand for EC2
capacity in the AWS region you're using. When the demand for EC2 capacity is high,
the price of Spot Instances increases. When the demand for EC2 capacity is low, the
price of Spot Instances decreases. If the Spot Instance is terminated by AWS because
the Spot price goes above the maximum price you set, you will only be charged for
the time the instance was running before it was terminated.

In summary, On-Demand Instances offer predictable pricing with no upfront costs,


while Spot Instances offer a much lower price but with variable pricing and
availability. Which one to choose depends on your application's requirements and
budget.

12
AWS Solutions Architect Professional Week-2

5.1 Scale the size of your Auto Scaling group:


Auto Scaling is a feature of Amazon Web Services (AWS) that allows you to
automatically adjust the capacity of your EC2 instances based on the demand for
your applications. This allows you to maintain optimal performance and reduce costs
by only running the number of instances needed to handle the current workload.

Scaling the size of an Auto Scaling group involves increasing or decreasing the
number of EC2 instances in the group. This can be done manually or automatically
based on predefined scaling policies.

To manually scale the size of an Auto Scaling group, you can use the AWS
Management Console, AWS CLI, or AWS SDK. You can specify the number of
instances you want to add or remove from the group, and the Auto Scaling group will
take care of launching or terminating the instances as needed.

To automatically scale the size of an Auto Scaling group, you need to define one or
more scaling policies. A scaling policy specifies the conditions under which the Auto
Scaling group should add or remove instances. For example, you might define a
scaling policy that adds two instances to the group when the average CPU utilization
across all instances exceeds 80% for a period of 5 minutes.

5.1.1 Scaling options:


Amazon EC2 Auto Scaling provides various scaling options that can be used to automatically
adjust the number of EC2 instances in an Auto Scaling group based on demand. These
scaling options are:

● Manual scaling: In this mode, you manually adjust the number of instances in the
Auto Scaling group. This is useful if you have predictable traffic patterns or if you
want to scale up or down in response to changes in demand.
● Scheduled scaling: With scheduled scaling, you can define a schedule to
automatically adjust the number of instances in an Auto Scaling group. This is useful
if you have known changes in demand based on the time of day, week, or month.
● Dynamic scaling: With dynamic scaling, you can configure Auto Scaling to
automatically adjust the number of instances in response to changes in demand. This
can be based on metrics such as CPU usage, network traffic, or custom metrics.
● Predictive scaling: Predictive scaling uses machine learning algorithms to predict
future demand and automatically adjust the number of instances in an Auto Scaling
group. This helps to ensure that you have the right number of instances to handle
the expected load.

13
AWS Solutions Architect Professional Week-2

● Instance refresh: With instance refresh, you can replace instances in an Auto Scaling
group with new instances that have the latest AMI (Amazon Machine Image) and
security patches. This helps to ensure that your instances are up-to-date and secure.
Manual scaling for Amazon EC2 Auto Scaling:
Manual scaling for Amazon EC2 Auto Scaling allows you to manually adjust the
desired capacity of an Auto Scaling group, which determines the number of EC2
instances running in the group. This feature is useful when you need to adjust the
number of instances in response to changes in demand or to perform maintenance
tasks.
You may use the AWS Management Console, the AWS Command Line Interface (CLI),
or the AWS SDKs to manually scale an Auto Scaling group. These are the
fundamental actions:

1. Open the Amazon EC2 console or run the AWS CLI command to view the
Auto Scaling groups available in your account.
2. Select the Auto Scaling group that you want to scale.
3. Choose "Edit Group Size" from the "Actions" menu.
4. In the "Desired Capacity" field, enter the new number of instances that you
want to run in the group.
5. Choose "OK" to save the changes.

After you have adjusted the desired capacity, Amazon EC2 Auto Scaling will launch or
terminate instances as needed to meet the new capacity target. It's important to note that
manual scaling is temporary and doesn't change the Auto Scaling group's scaling policies or
the number of instances that will be launched or terminated in response to automatic
scaling events.

Dynamic scaling for Amazon EC2 Auto Scaling

Dynamic scaling for Amazon EC2 Auto Scaling refers to the ability of the service to
automatically adjust the number of EC2 instances running in response to changes in demand
or traffic to an application. It allows you to define scaling policies that automatically add or
remove EC2 instances from your Auto Scaling group based on metrics such as CPU
utilization, network traffic, or custom application metrics.

The dynamic scaling process begins by defining a set of scaling policies that specify the
desired behavior for scaling the Auto Scaling group. These policies can be based on simple
thresholds or more complex algorithms that consider multiple metrics and factors. Once the
policies are defined, EC2 Auto Scaling continually monitors the metrics and automatically
adjusts the number of EC2 instances in the group to meet the defined capacity
requirements.

14
AWS Solutions Architect Professional Week-2

Dynamic scaling provides a flexible and cost-effective way to ensure that your application
can handle varying levels of traffic and demand. By automatically adding or removing
instances, you can optimize your resource usage and ensure that your application remains
responsive and available to users.

Predictive scaling for Amazon EC2 Auto Scaling

Predictive scaling for Amazon EC2 Auto Scaling is a feature that uses machine learning to
automatically adjust the number of EC2 instances in an Auto Scaling group based on
predicted demand. It can help you optimize resource usage and ensure that your application
is responsive and available to users even during unexpected spikes in traffic.
Predictive scaling works by analyzing historical patterns and trends in your application's
demand and predicting future demand based on that data. It considers factors such as time
of day, day of the week, and seasonality to identify recurring patterns in traffic. It then uses
this data to forecast future demand and adjust the capacity of your Auto Scaling group
accordingly.

With predictive scaling, you can set a target level of utilization for your Auto Scaling group,
and the feature will automatically adjust the number of instances to meet that target. For
example, if predictive scaling predicts that your application will experience a sudden
increase in demand in the next hour, it will proactively add instances to the Auto Scaling
group to ensure that capacity is available to handle the incoming traffic.

Predictive scaling can be used in conjunction with other scaling policies, such as target
tracking or simple scaling, to provide a comprehensive scaling solution for your application.
By using predictive scaling, you can reduce the likelihood of overprovisioning or
underprovisioning resources and ensure that your application is always ready to handle the
demands of your users.

Amazon EC2 Auto Scaling lifecycle hooks:

Amazon EC2 Auto Scaling lifecycle hooks are a feature that allows you to customize the
behavior of your Auto Scaling group during scale-out and scale-in events. Lifecycle hooks
enable you to perform actions before an instance is launched or terminated, such as
configuring it or draining it off connections.

When you create an Auto Scaling group, you can specify one or more lifecycle hooks. These
hooks can be used to monitor the progress of an instance as it launches or terminates and
to take action at various stages of the process.
Lifecycle hooks come in the "before launch" and "after terminate" varieties.

Before launch hooks are used to configure an instance before it is launched. For example,
you might use a before-launch hook to install software or update configurations on the
instance before it becomes available for use.

15
AWS Solutions Architect Professional Week-2

After termination hooks are used to perform actions after an instance has been terminated.
For example, you might use an after-terminate hook to remove the instance from a load
balancer, or to clean up resources associated with the instance.

Lifecycle hooks can be useful for a variety of scenarios, such as ensuring that all instances in
an Auto Scaling group are properly configured, or gracefully draining connections from an
instance before it is terminated. By using lifecycle hooks, you can customize the behavior of
your Auto Scaling group to fit the needs of your application or workload.

Warm pools for Amazon EC2 Auto Scaling

Amazon EC2 Auto Scaling provides the ability to automatically scale your Amazon Elastic
Compute Cloud (EC2) capacity up or down according to the conditions you define. This can
help ensure that your applications have the necessary resources to handle fluctuations in
demand without overprovisioning and wasting resources.

When launching new EC2 instances as part of an Auto Scaling group, you can specify that
the instances should be launched in a "warm pool". A warm pool is a set of pre-provisioned
EC2 instances that are not currently in use but are ready to be added to the Auto Scaling
group as soon as demand increases.
Launching instances in a warm pool can help reduce the time it takes for the Auto Scaling
group to respond to increased demand. Instead of waiting for new instances to launch and
become available, the Auto

5.2 Set capacity limits on your Auto Scaling group:


Auto Scaling is a service provided by Amazon Web Services (AWS) that automatically adjusts
the number of EC2 instances in an Auto Scaling group based on predefined rules or metrics.
One important aspect of setting up an Auto Scaling group is configuring its capacity limits,
which determine the minimum and maximum number of instances that the group can have
at any given time.
Setting capacity limits is crucial because it helps ensure that the Auto Scaling group can scale
up and down effectively to meet the demand for your application or service. Here are some
key considerations when setting capacity limits for your Auto Scaling group:

● Minimum size: This is the minimum number of instances that your Auto
Scaling group can have. It's important to set this value high enough to ensure
that your application can handle the expected traffic and workload, but not
so high that it incurs unnecessary costs.

16
AWS Solutions Architect Professional Week-2

● Maximum size: This is the maximum number of instances that your Auto
Scaling group can have. You'll want to set this value to accommodate the
highest expected traffic or workload, but not so high that it incurs
unnecessary costs.

● Desired capacity: This is the number of instances that your Auto Scaling group
should aim to maintain at all times. This value should be between the
minimum and maximum sizes you've set.

● Scaling policies: You can configure scaling policies that automatically adjust
the number of instances in your Auto Scaling group based on certain
conditions, such as CPU utilization or network traffic. These policies can help
ensure that your application can handle sudden spikes in traffic or workload.

By setting appropriate capacity limits for your Auto Scaling group and configuring scaling
policies, you can ensure that your application or service can scale up and down effectively,
while minimizing costs and maintaining optimal performance.

6. Monitor your Auto Scaling instances and groups


Amazon EC2 Auto Scaling is a service that enables you to automatically launch or terminate
EC2 instances based on the dynamic demands of your application. As your application load
increases, EC2 Auto Scaling can launch new instances, and as the load decreases, it can
terminate unnecessary instances. Monitoring is a critical aspect of EC2 Auto Scaling that
allows you to monitor the health and performance of your EC2 instances and Auto Scaling,
groups.
Monitoring in EC2 Auto Scaling involves setting up various monitoring tools and services to
track the performance and health of your EC2 instances and Auto Scaling, groups. Some of
the key monitoring tools and services you can use include Amazon CloudWatch, AWS
CloudTrail, and AWS Config.

Amazon CloudWatch provides monitoring for your EC2 instances and Auto Scaling groups by
collecting and tracking metrics such as CPU utilization, network traffic, and disk usage. You
can use CloudWatch to set up alarms that trigger based on specific thresholds or conditions,
so you can quickly respond to issues or take action to scale your instances up or down.

AWS CloudTrail is another monitoring tool that provides visibility into user activity by
recording API calls and related events. This allows you to see who has accessed your
resources, when they accessed them, and what actions they performed. With CloudTrail,
you can audit and monitor the changes made to your Auto Scaling groups and instances,
helping you maintain a secure and compliant environment.

17
AWS Solutions Architect Professional Week-2

Finally, AWS Config provides a detailed inventory of your AWS resources, including EC2
instances and Auto Scaling groups. This allows you to track changes to your resources over
time and ensure that they comply with your organization's policies and best practices.
In summary, monitoring in EC2 Auto Scaling involves using various monitoring tools and
services to track the performance and health of your EC2 instances and Auto Scaling,
groups. With these tools, you can quickly respond to issues, scale your instances up or down
as needed, and maintain a secure and compliant environment.

7. Lab Get started with Amazon EC2 Auto Scaling


Step 1: Create a launch template
Open the Amazon EC2 console and navigate to the EC2 Auto Scaling groups page.

Click on the "Create launch template" button to start creating a new launch template.

18
AWS Solutions Architect Professional Week-2

● Select an
Amazon
Machine
Image (AMI)
for your
instances.
This will
determine
the base
operating
system and software that will be installed on your instances.
● Choose an instance type that meets the requirements of your application.

● Configure the network settings for your instances, including VPC, subnet, security group,
and IP addresses.
● Specify any additional instance configuration details, such as instance metadata, user
data scripts, and IAM roles.
● Review and confirm the details of your launch template.

● Save the launch template.

19
AWS Solutions Architect Professional Week-2

Step 2: Create a
single-instance
Auto Scaling
group

Creating a single-
instance Auto
Scaling group in
EC2 Auto Scaling
involves setting up
a configuration that enables an EC2 instance to be automatically launched and terminated based on
predefined scaling policies.

20
AWS Solutions Architect Professional Week-2

Here are the


steps to create
a single-instance Auto Scaling group:

1. Go to the Auto Scaling Groups page in the Amazon EC2 interface.

2. Press the button labeled Create Auto Scaling Group.

3. Decide which launch template to apply to the Auto Scaling group.

4. Because you only want to build a single-instance Auto Scaling group, set the group size to 1.

21
AWS Solutions Architect Professional Week-2

5. Set the instance's network preferences and security groups.

6. Decide on the group's scaling strategies, such as how many instances to add or delete in response
to indicators like CPU utilization.

In the "Create
scaling policy" page, choose a policy type: either "Target tracking scaling" or "Step scaling".

- Target tracking scaling policy allows you to automatically adjust the number of instances in the
Auto Scaling group to maintain a specific metric at a target value, such as CPU utilization or network
traffic.

- Step scaling policy allows you to define scaling adjustments based on a set of scaling metrics and
thresholds.

22
AWS Solutions Architect Professional Week-2

7. After checking and confirming the Auto Scaling group's specifics, click Create Auto Scaling Group.

Step 3: Verify your Auto Scaling group

23
AWS Solutions Architect Professional Week-2

Now Connect to the Ec2 instance and increase the CPU Utilization

Choose the second tab, Activity. Under Activity History33 you can view the progress of activities that
are associated with the Auto Scaling group.

24
AWS Solutions Architect Professional Week-2

You may monitor the instance's status under Instances on the Instance Management tab.

Step 4: Terminate an instance in your Auto Scaling group

8. Case Study: AWS EC2 Autoscaling for E-Commerce Application


Introduction:

In this case study, we will examine a project undertaken by a leading e-commerce


organization to address the scalability and availability challenges of their application. The
organization experienced frequent spikes in traffic during peak periods, resulting in slow
response times and occasional downtime. To mitigate these issues, they decided to
implement AWS EC2 autoscaling to dynamically adjust their infrastructure capacity based on
demand.

25
AWS Solutions Architect Professional Week-2

Challenges:

The e-commerce organization faced several challenges:

1. Unpredictable Traffic Patterns: The application experienced highly variable traffic patterns
throughout the day, with sudden spikes during promotional events or holidays. The existing
infrastructure struggled to handle these traffic surges efficiently, leading to a degraded user
experience.

2. Scalability: The organization needed a solution that could seamlessly scale up or down
based on demand to ensure optimal performance during peak periods and minimize costs
during off-peak times.

3. High Availability: Downtime during peak traffic periods was a significant concern. The
organization required a solution that could maintain a high availability and minimize the
impact of any potential failures.

Solution:

To address these challenges, the organization implemented AWS EC2 autoscaling along with
other complementary services:

1. EC2 Autoscaling Groups: The organization created an autoscaling group to define the
desired capacity for their EC2 instances. They set up scaling policies based on metrics such
as CPU utilization, network traffic, or custom application-specific metrics to automatically
add or remove instances.

2. Elastic Load Balancer (ELB): To distribute incoming traffic evenly across the EC2 instances,
an Elastic Load Balancer was configured. The ELB automatically registered new instances
added by the autoscaling group and removed instances when they were terminated.

3. Amazon CloudWatch: The organization utilized CloudWatch to monitor the application's


performance and collect metrics on CPU utilization, network traffic, and request latency.
These metrics were used as triggers for autoscaling actions, ensuring that the infrastructure
dynamically adjusted to meet demand.

Results:

The implementation of AWS EC2 autoscaling provided significant benefits to the e-


commerce organization:

1. Improved Performance: The organization observed a notable improvement in application


performance during peak traffic periods. With the ability to scale up capacity automatically,
response times remained consistently fast, providing a seamless user experience.

26
AWS Solutions Architect Professional Week-2

2. Cost Optimization: By utilizing EC2 autoscaling, the organization optimized costs by scaling
down the infrastructure during periods of low demand. This allowed them to pay only for
the resources they needed, reducing overall infrastructure expenses.

3. Enhanced Availability: The use of autoscaling and load balancing improved the
application's availability. Even in the event of an instance failure, the autoscaling group
automatically launched replacement instances, minimizing any potential downtime.

4. Operational Efficiency: The automation provided by EC2 autoscaling reduced the


organization's operational burden. They no longer needed manual intervention to handle
traffic surges or adjust capacity, allowing their engineering team to focus on other critical
tasks.

Learnings and Conclusion:

This case study demonstrates the effectiveness of AWS EC2 autoscaling in addressing
scalability and availability challenges for e-commerce applications. Key learnings from this
project include

1. Scalability on Demand: Autoscaling provides the ability to seamlessly adjust infrastructure


capacity based on demand, ensuring optimal performance and cost efficiency.

2. Automation and Monitoring: Leveraging automation tools like EC2 autoscaling and
CloudWatch enables organizations to maintain high availability, optimize costs, and
streamline operations.

3. Flexibility and Resilience: By combining autoscaling with load balancing, organizations can
achieve greater resilience against failures and provide uninterrupted service to their users.

4. Ongoing Optimization: Regular monitoring and fine-tuning of autoscaling policies and


thresholds are essential to ensure optimal performance and cost savings.

In conclusion, AWS EC2 autoscaling, along with complementary services, offers a robust
solution for managing variable workloads and achieving high availability for applications. By
implementing autoscaling, organizations can scale their infrastructure dynamically, provide
an excellent user experience, optimize costs, and reduce operational overhead.

27

You might also like