Skip to main content

AWS Auto Scaling Testing and Tuning

Hands-On Lab

 

Photo of Craig Arcuri

Craig Arcuri

AWS Training Architect II in Content

Length

00:30:00

Difficulty

Intermediate

Welcome to this hands-on AWS Learning Activity in which you will learn how to Test and Tuning Auto Scaling in AWS. Auto Scaling Groups provide the flexibility to scale up and scale down resources (EC2 Instances), as dictated by the load placed on these resources. Part of being a trained DevOps professional includes the ability to properly set up, configure, and test proper ASG workloads. In this activity, we will set CloudWatch alarms to scale up/down based on CPU Utilization, but rather than simply trusting that our ASG will work properly, we will install a stress tool to test our ASG. This will ensure that it scales up and down accordingly and provide the opportunity to tune our ASG, the alarms, and even cooldown periods based on the test results.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

AWS Auto Scaling Testing and Tuning

Auto Scaling groups provide the flexibility to scale up and scale down resources (EC2 instances) as dictated by the load placed on these resources. Part of being a trained DevOps professional includes the ability to properly set up, configure, and test proper Auto Scaling group workloads.

In this hands-on lab, we will set CloudWatch alarms to scale up/down based on CPU utilization, but rather than simply trusting that our Auto Scaling group will work properly, we will install a stress tool to test our Auto Scaling group. This will ensure it scales up and down accordingly and provide the opportunity to tune our Auto Scaling group, the alarms, and even cooldown periods based on the test results.

Please log in to the AWS environment by using the cloud_user credentials provided.

Once inside the AWS account, make sure you are using us-east-1 (N. Virginia) as the selected region.

Create a Launch Configuration and an Auto Scaling Group

First, we'll create one Auto Scaling launch configuration.

Create Launch Configuration

In the AWS Management Console Dashboard, navigate to EC2. Select Launch Configurations in the sidebar, found in the Auto Scaling section.

Click Create launch configuration.

Select Amazon Linux AMI and then t2.micro. Click Next: Configure details.

On the details page, name it testandtuneASG. Under Advanced Details, check the Assign a public IP address to every instance. radio button. Click Skip Storage.

Click Review.

If the details of your launch configuration look correct, click Create launch configuration.

From the dropdown, select Create a new key pair, name it test and tune, and click Download Key Pair.

Click Create launch configuration.

Create Auto Scaling Group

Click the Create an Auto Scaling group based on this launch configuration button.

  • Group name: tntASG
  • Group size: Leave default, 1
  • Network: Default VPC in dropdown
  • Subnet: Select one of the options that appear in dropdown

Click Next: Configure scaling policies.

Select the radio button Use scaling policies to adjust the capacity of this group.

Set to scale between 1 and 2 instances.

Click Scale the Auto Scaling group using step or simple scaling policies.

Under Increase Group Size, click Add new alarm.

De-select Send a notification to:.

  • Whenever: Average of CPU Utilization
  • Is: >= 60 Percent
  • For at least: 1 consecutive period(s) of 5 Minutes
  • Name of alarm: leave default
  • Create Alarm

Back under Increase Group Size:

Take the Action: Add 1 instance

Under Decrease Group Size, click Add new alarm.

De-select Send a notification to:.

  • Whenever: Average of CPU Utilization
  • Is: <= 40 Percent
  • For at least: 1 consecutive period(s) of 5 Minutes
  • Name of alarm: Leave default
  • Create Alarm

Back under Decrease Group Size:

Take the Action: Remove 1 instance

Click Review

Click Create Auto Scaling group.

Click View your Auto Scaling groups and monitor your Activity History and Instances tabs.

Navigate to the EC2 Dashboard in the sidebar and click Running Instances to list instances. Click Connect. Copy the ssh command to log in to your EC2 instance in the next step. Paste it in to a note on your desktop because we'll need it soon.

Installing and Running a Stress Tool to Test an Auto Scaling Group

Keep the AWS Console open and navigate back to Auto Scaling Groups in the sidebar to keep an eye on it during the stress test. While stressing the CPU, monitor your Auto Scaling group's Activity History and Instances tabs in the AWS Console to ensure proper scaling actions.

Now, open up a terminal window and make sure you're in your Downloads folder. Let's change the permissions on our key pair we downloaded earlier.

cd ~/Downloads
chmod 400 testandtune.pem

Paste in and enter the ssh command you copied before.

As an example:

ssh -i testandtune.pem ec2-user@ec2-34-228-219-73.compute-1.amazonaws.com

When asked if you're sure you want to continue connecting, enter:

yes

To apply updates, enter:

sudo yum update

When asked if this is ok, enter:

y

The Amazon Linux 2 AMI does not have the stress tool, so we need to run this command before installing it:

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Install the stress package:

sudo yum install stress -y

To run the stress tool, enter:

sudo stress --cpu 1 --timeout 320 &amp;

Enter:

top

This command will monitor the process created by the stress tool, which will run for 5 minutes and 20 seconds, and monitor CPU utilization, which should remain very near 100% for that amount of time.

After the stress process completes, continue to monitor your Auto Scaling group's Activity History and Instances tabs to ensure proper scale down.

Conclusion

Congratulations on completing this lab!