

# Use scheduled actions to scale Amazon ECS services
Schedule scaling

With scheduled scaling, you can set up automatic scaling for your application based on predictable load changes by creating scheduled actions that increase or decrease the number of tasks at specific times. This allows you to scale your application proactively to match predictable load changes.

These scheduled scaling actions allow you to optimize costs and performance. Your application has a sufficient number of tasks to handle the mid-week traffic peak, but does not over-provision the number of tasks at other times. 

You can use scheduled scaling and scaling policies together to get the benefits of proactive and reactive approaches to scaling. After a scheduled scaling action runs, the scaling policy can continue to make decisions about whether to further scale the number of tasks. This helps you ensure that you have a sufficient number of tasks to handle the load for your application. While your application scales to match demand, current capacity must fall within the minimum and maximum number of tasks that was set by your scheduled action. 

You can configure schedule scaling using the AWS CLI. For more information about scheduled scaling, see [Scheduled Scaling](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html) in the *Application Auto Scaling User Guide*.

# Create a scheduled action for Amazon ECS service auto scaling
Create a scheduled action

Create a scheduled action to have Amazon ECS increase or decrease the number of tasks that your service runs based on the date and time. 

## Console


1. Open the console at [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2).

1. On the **Clusters** page, choose the cluster.

1. On the cluster details page, in the **Services** section, choose the service.

   The service details page appears.

1. Choose **Service auto scaling**.

   The service auto scaling page appears.

1. If you haven't configured service auto scaling, choose **Set the number of tasks**.

   The **Amazon ECS service task count** section appears.

   Under **Amazon ECS service task count**, choose **Use service auto scaling to adjust your service's desired task count**.

   The **Task count section** appears.

   1. For **Minimum number of tasks**, enter the lower limit of the number of tasks for service auto scaling to use. The desired count will not go below this count.

   1. For **Maximum**, enter the upper limit of the number of tasks for service auto scaling to use. The desired count will not go above this count.

   1. Choose **Choose Save**.

      The policies page appears.

1. Choose **Scheduled actions**, and then choose **Create**.

   The **Create Scheduled action** page appears.

1. For **Action name**, enter a unique name.

1. For **Time zone**, choose a time zone.

   All of the time zones listed are from the IANA Time Zone database. For more information, see [List of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).

1. For **Start time**, enter the **Date** and **Time** the action starts.

   If you chose a recurring schedule, the start time defines when the first scheduled action in the recurring series runs.

1. For **Recurrence**, choose one of the available options.
   + To scale on a recurring schedule, choose how often Amazon ECS runs the scheduled action.
     + If you choose an option that begins with **Rate**, the cron expression is created for you.
     + If you choose **Cron**, enter a cron expression that specifies when to perform the action. 
   + To scale only once, choose **Once**.

1. Under **Task adjustments**, do the following:
   + For **Minimum**, enter the minumum number of tasks the service should run.
   + For **Maximum**, enter the maximum number of tasks the service should run.

1. Choose **Create scheduled action**.

## CLI


Use the AWS CLI as follows to configure scheduled scaling policies for your service. Replace each *user input placeholder* with your own information.

**Example: To scale one time only**  
Use the following [put-scheduled-action](https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/put-scheduled-action.html) command with the `--start-time "YYYY-MM-DDThh:mm:ssZ"` and and either or both of the `--MinCapacity` and `--MaxCapacity` options. 

```
aws application-autoscaling put-scheduled-action --service-namespace ecs \
  --resource-id service/my-cluster/my-service \
  --scheduled-action-name my-one-time-schedule \
  --start-time 2021-01-30T12:00:00 \
  --scalable-target-action MinCapacity=3,MaxCapacity=10
```

**Example: To schedule scaling on a recurring schedule**  
Use the following [put-scheduled-action](https://docs.aws.amazon.com/cli/latest/reference/application-autoscaling/put-scheduled-action.html) command. Replace the *user input* with your values.

```
aws application-autoscaling put-scheduled-action --service-namespace ecs \
  --resource-id service/my-cluster/my-service \
  --scheduled-action-name my-recurring-action \
  --schedule "rate(5 hours)" \
  --start-time 2021-01-30T12:00:00 \
  --end-time 2021-01-31T22:00:00 \
  --scalable-target-action MinCapacity=3,MaxCapacity=10
```

The specified recurrence schedule runs based on the UTC time zone. To specify a different time zone, include the `--time-zone` option and the name of the IANA time zone, as in the following example.

```
--time-zone "America/New_York"
```

For more information, see [List of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).