Amazon Elastic Container Service
Developer Guide (API Version 2014-11-13)

Step 5: (Optional) Configuring Your Service to Use Service Auto Scaling

Your Amazon ECS service can optionally be configured to use Auto Scaling to adjust its desired count up or down in response to CloudWatch alarms.

Amazon ECS Service Auto Scaling supports the following types of scaling policies:

  • Target Tracking Scaling Policies—Increase or decrease
 the number of tasks that your service runs based on a target value for a specific metric. This is similar to the way that your thermostat maintains the temperature of your home. You select temperature and the thermostat does the rest.

  • Step Scaling Policies—Increase or decrease the number of tasks that your service runs based on a set of scaling adjustments, known as step adjustments, which vary based on the size of the alarm breach.

For more information, see Service Auto Scaling.

To configure basic Service Auto Scaling parameters

  1. If you have not done so already, follow the basic service configuration procedures in Step 1: Configuring Basic Service Parameters.

  2. On the Set Auto Scaling page, select Configure Service Auto Scaling to adjust your service’s desired count.

  3. For Minimum number of tasks, enter the lower limit of the number of tasks for Service Auto Scaling to use. Your service's desired count is not automatically adjusted below this amount.

  4. For Desired number of tasks, this field is pre-populated with the value that you entered earlier. You can change your service's desired count at this time, but this value must be between the minimum and maximum number of tasks specified on this page.

  5. For Maximum number of tasks, enter the upper limit of the number of tasks for Service Auto Scaling to use. Your service's desired count is not automatically adjusted above this amount.

  6. For IAM role for Service Auto Scaling, choose an IAM role to authorize the Application Auto Scaling service to adjust your service's desired count on your behalf. If you have not previously created such a role, choose Create new role and the role is created for you. For future reference, the role that is created for you is called ecsAutoscaleRole. For more information, see Amazon ECS Service Auto Scaling IAM Role.

  7. The following procedures provide steps for creating either target tracking or step scaling policies for your service. Choose your desired scaling policy type.

These steps help you create target tracking scaling policies and CloudWatch alarms that can be used to trigger scaling activities for your service. You can create a scale-out alarm to increase the desired count of your service, and a scale-in alarm to decrease the desired count of your service.

To configure target tracking scaling policies for your service

  1. For Scaling policy type, choose Target tracking.

  2. For Policy name, enter a descriptive name for your policy.

  3. For ECS service metric, choose the metric to track.

  4. For Target value, enter the metric value that the policy should maintain.

  5. For Scale-out cooldown period, enter the amount of time, in seconds, after a scale-out activity completes before another scale-out activity can start. During this time, resources that have been launched do not contribute to the Auto Scaling group metrics.

  6. For Scale-in cooldown period, enter the amount of time, in seconds, after a scale-in activity completes before another scale-in activity can start. During this time, resources that have been launched do not contribute to the Auto Scaling group metrics.

  7. (Optional) To disable the scale-in actions for this policy, choose Disable scale-in. This allows you to create a separate scaling policy for scale-in later.

  8. Choose Next step.

These steps help you create step scaling policies and CloudWatch alarms that can be used to trigger scaling activities for your service. You can create a Scale out alarm to increase the desired count of your service, and a Scale in alarm to decrease the desired count of your service.

To configure step scaling policies for your service

  1. For Scaling policy type, choose Step scaling.

  2. For Policy name, enter a descriptive name for your policy.

  3. For Execute policy when, select the CloudWatch alarm to use to scale your service up or down.

    You can use an existing CloudWatch alarm that you have previously created, or you can choose to create a new alarm. The Create new alarm workflow allows you to create CloudWatch alarms that are based on the CPUUtilization and MemoryUtilization of the service that you are creating. To use other metrics, you can create your alarm in the CloudWatch console and then return to this wizard to choose that alarm.

  4. (Optional) If you've chosen to create a new alarm, complete the following steps.

    1. For Alarm name, enter a descriptive name for your alarm. For example, if your alarm should trigger when your service CPU utilization exceeds 75%, you could call the alarm service_name-cpu-gt-75.

    2. For ECS service metric, choose the service metric to use for your alarm. For more information, see Service Utilization.

    3. For Alarm threshold, enter the following information to configure your alarm:

      • Choose the CloudWatch statistic for your alarm (the default value of Average works in many cases). For more information, see Statistics in the Amazon CloudWatch User Guide.

      • Choose the comparison operator for your alarm and enter the value that the comparison operator checks against (for example, > and 75).

      • Enter the number of consecutive periods before the alarm is triggered and the period length. For example, two consecutive periods of 5 minutes would take 10 minutes before the alarm triggered. Because your Amazon ECS tasks can scale up and down quickly, consider using a low number of consecutive periods and a short period duration to react to alarms as soon as possible.

    4. Choose Save.

  5. For Scaling action, enter the following information to configure how your service responds to the alarm:

    • Choose whether to add to, subtract from, or set a specific desired count for your service.

    • If you chose to add or subtract tasks, enter the number of tasks (or percent of existing tasks) to add or subtract when the scaling action is triggered. If you chose to set the desired count, enter the desired count that your service should be set to when the scaling action is triggered.

    • (Optional) If you chose to add or subtract tasks, choose whether the previous value is used as an integer or a percent value of the existing desired count.

    • Enter the lower boundary of your step scaling adjustment. By default, for your first scaling action, this value is the metric amount where your alarm is triggered. For example, the following scaling action adds 100% of the existing desired count when the CPU utilization is greater than 75%.

      
                                Scaling activity example
  6. (Optional) You can repeat Step 5 to configure multiple scaling actions for a single alarm (for example, to add one task if CPU utilization is between 75-85%, and to add two tasks if CPU utilization is greater than 85%).

  7. (Optional) If you chose to add or subtract a percentage of the existing desired count, enter a minimum increment value for Add tasks in increments of N task(s).

  8. For Cooldown period, enter the number of seconds between scaling actions.

  9. Repeat Step 1 through Step 8 for the Scale in policy and choose Save.

  10. Choose Next step to proceed and navigate to Step 6: Review and Create Your Service.