Skip to main content

Configuring Auto Scaling Rules for an AWS Fargate Cluster

Hands-On Lab

 

Photo of Mark Richman

Mark Richman

AWS Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

In this hands-on learning activity, the student will configure auto scaling rules for a service, and trigger those rules by applying a load to that service.

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.

Configuring Autoscaling Rules for an AWS Fargate Cluster

Introduction

In this hands-on lab, we will configure auto scaling rules for a service and trigger those rules by applying a load to that service.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

You'll need to use the ApacheBench (ab) utility later on. This command is installed by default on macOS, and it is also available for many Linux distributions. For example, you can install ab on Amazon Linux with the following command:

   sudo yum install -y httpd24-tools

Configure Service Auto Scaling

  1. In the AWS console, navigate to ECS and click the listed cluster.
  2. In the Services section, click to open the webapp service.
  3. Click Update.
  4. Click Next step on the Configure service and Configure network pages.
  5. For Service Auto Scaling, choose Configure Service Auto Scaling to adjust your service’s desired count.
  6. Set the following values:
    • Minimum number of tasks: 1
    • Desired number of tasks: 1
    • Maximum number of tasks 2
    • IAM role for Service Auto Scaling: Choose the listed role
  7. Click Add scaling policy.
  8. On the Add policy page, set the following values:
    • Scaling policy type: Target tracking
    • Policy name: TargetTrackingPolicy
    • *ECS service metric: CPUUtilization**
    • Target value: 75
    • Scale-out cooldown period: 60
    • Scale-in cooldown period: 60
  9. Click Save.
  10. Click Next step.
  11. Review, and then click Update Service.
  12. When your service status is finished updating, click View Service.

Trigger a Scaling Activity for Your Service

  1. From your service's main view page in the console, choose the load balancer name to view its details in the Amazon EC2 console. You need the load balancer's DNS name.

  2. Use the ApacheBench (ab) utility to make thousands of HTTP requests to your load balancer in a short period of time.

  3. Run the following command, substituting your load balancer's DNS name.

    ab -n 1000000 -c 2000 http://<YOUR_ALB_ENDPOINT_HERE>.us-east-1.elb.amazonaws.com/
  4. In the AWS console, navigate to CloudWatch.

  5. Click Alarms in the left-hand menu.

  6. Wait for your ab HTTP requests to trigger the scale-out alarm in the CloudWatch console. You should see your Amazon ECS service scale out and add one task to your service's desired count.

  7. Shortly after your ab HTTP requests complete (>= 10 mins), your scale-in alarm should trigger. The scale-in policy should reduce your service's desired count back to one.

Conclusion

Congratulations on completing this hands-on lab!