

# Using Amazon EventBridge Scheduler to schedule Amazon ECS tasks
<a name="tasks-scheduled-eventbridge-scheduler"></a>

EventBridge Scheduler is a serverless scheduler that allows you to create, run, and manage tasks from one central, managed service. It provides one-time and recurring scheduling functionality independent of event buses and rules. EventBridge Scheduler is highly customizable, and offers improved scalability over EventBridge scheduled rules, with a wider set of target API operations and AWS services. EventBridge Scheduler provides the following schedules which you can configure for your tasks in the EventBridge Scheduler console:
+ Rate-based 
+ Cron-based

  You can configure cron-based schedules in any time zone.
+ One-time schedules

  You can configure one-time schedules in any time zone.

You can schedule your Amazon ECS using Amazon EventBridge Scheduler.

Although you can create a scheduled task in the Amazon ECS console, currently the EventBridge Scheduler console provides more functionality.

Complete the following steps before you schedule a task:

1. Use the VPC console to get the subnet IDs where the tasks run and the security group IDs for the subnets. For more information, see [Subnets for your VPC](https://docs.aws.amazon.com/vpc/latest/userguide/configure-subnets.html), and [Control traffic to your AWS resources using security groups](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html) in the *Amazon VPC User Guide*.

1. Configure the EventBridge Scheduler execution role. For more information, see [Set up the execution role](https://docs.aws.amazon.com/scheduler/latest/UserGuide/setting-up.html#setting-up-execution-role) in the *Amazon EventBridge Scheduler User Guide*. 

1. If you want to use a capacity provider strategy to run the task, you must have a capacity provider associated with the cluster.

**To create a new schedule using the console**

1. Open the Amazon EventBridge Scheduler console at [https://console.aws.amazon.com/scheduler/home](https://console.aws.amazon.com/scheduler/home/).

1.  On the **Schedules** page, choose **Create schedule**. 

1.  On the **Specify schedule detail** page, in the **Schedule name and description** section, do the following: 

   1. For **Schedule name**, enter a name for your schedule. For example, **MyTestSchedule**. 

   1. (Optional) For **Description**, enter a description for your schedule. For example, **TestSchedule**.

   1. For **Schedule group**, choose a schedule group. If you don't have a group, choose **default**. To create a schedule group, choose **create your own schedule**. 

      You use schedule groups to add tags to groups of schedules. 

1. Choose your schedule options.


<table>
<thead>
  <tr><th>Occurrence</th><th>Do this...</th><th></th></tr>
</thead>
<tbody>
  <tr><td><b>One-time schedule</b><br />A one-time schedule invokes a target only once at the date and time that you specify. </td><td>For <b>Date and time</b>, do the following:<ul><li> Enter a valid date in <code>YYYY/MM/DD</code> format. </li><li> Enter a timestamp in 24-hour <code>hh:mm</code> format. </li><li> For <b>Timezone</b>, choose the timezone. </li></ul></td><td></td></tr>
  <tr><td><b>Recurring schedule</b><br />A recurring schedule invokes a target at a rate that you specify using a <b>cron</b> expression or rate expression. </td><td> <ol><li> For <b>Schedule type</b>, do one of the following: <ul><li> To use a cron expression to define the schedule, choose <b>Cron-based schedule</b> and enter the cron expression. </li><li> To use a rate expression to define the schedule, choose <b>Rate-based schedule</b> and enter the rate expression. <br />For more information about cron and rate expressions, see <a href="https://docs.aws.amazon.com/scheduler/latest/UserGuide/schedule-types.html#cron-based">Schedule types on EventBridge Scheduler</a> in the <i>Amazon EventBridge Scheduler User Guide</i>.  </li></ul> </li><li> For <b>Flexible time window</b>, choose <b>Off</b> to turn off the option, or choose one of the pre-defined time windows. For example, if you choose <b>15 minutes</b> and you set a recurring schedule to invoke its target once every hour, the schedule runs within 15 minutes after the start of every hour.  </li></ol> </td><td></td></tr>
</tbody>
</table>


1. (Optional) If you chose **Recurring schedule** in the previous step, in the **Timeframe** section, do the following: 

   1. For **Timezone**, choose a timezone. 

   1. For **Start date and time**, enter a valid date in `YYYY/MM/DD` format, and then specify a timestamp in 24-hour `hh:mm` format. 

   1. For **End date and time**, enter a valid date in `YYYY/MM/DD` format, and then specify a timestamp in 24-hour `hh:mm` format. 

1. Choose **Next**. 

1. On the **Select target** page, do the following: 

   1. Choose **All APIs**, and then in the search box enter **ECS**. 

   1. Select **Amazon ECS**.

   1. In the search box, enter **RunTask**, and then choose **RunTask**.

   1. For **ECS cluster**, choose the cluster.

   1. For **ECS task**, choose the task definition to use for the task.

   1. Choose how your tasks are distributed across your cluster infrastructure. Expand **Compute options**, and then choose one of the following options


<table>
<thead>
  <tr><th>Compute option</th><th>Steps</th><th></th></tr>
</thead>
<tbody>
  <tr><td>Capacity provider strategy</td><td> <ol><li> Choose <b>Capacity provider strategy</b>. </li><li> Choose a strategy: <ul><li> To use the default capacity provider strategy, choose <b>Use cluster default</b>. </li><li> To use a custom strategy, choose <b>Use custom</b>. Then, enter the <b>Base</b>, <b>Capacity provider</b>, and <b>Weight</b>. <br />For EC2, the Capacity provider is the Auto Scaling group. </li></ul> </li></ol> </td><td></td></tr>
  <tr><td>Launch type</td><td> <ol><li> Choose <b>Launch type</b>. </li><li> For <b>Launch type</b>, choose a launch type. </li><li> When the Fargate is specified, for <b>Platform version</b>, specify the platform version to use. </li></ol> </td><td></td></tr>
</tbody>
</table>


   1. For **Subnets**, enter the subnet IDs to run the task in.

   1. For **Security groups**, enter the security group IDs for the subnet.

   1. (Optional) To use a task placement strategy other than the default, expand **Placement constraint**, and then enter the constraints.

       For more information, see [How Amazon ECS places tasks on container instances](task-placement.md).

   1. (Optional) To help identify your tasks, under **Tags** configure your tags.

      To have Amazon ECS automatically tag all newly launched tasks with the task definition tags, select **Enable Amazon ECS managed tags**.

1. Choose **Next**. 

1. On the **Settings** page, do the following: 

   1. To turn on the schedule, under **Schedule state**, toggle **Enable schedule**. 

   1. To configure a retry policy for your schedule, under **Retry policy and dead-letter queue (DLQ)**, do the following:
      + Toggle **Retry**.
      + For **Maximum retention time of event**, enter the maximum **hour(s)** and **min(s)** that EventBridge Scheduler must keep an unprocessed event.
      + The maximum time is 24 hours.
      + For **Maximum retries**, enter the maximum number of times EventBridge Scheduler retries the schedule if the target returns an error. 

         The maximum value is 185 retries. 

      With retry policies, if a schedule fails to invoke its target, EventBridge Scheduler re-runs the schedule. If configured, you must set the maximum retention time and retries for the schedule.

   1. Choose where EventBridge Scheduler stores undelivered events. 


<table>
<thead>
  <tr><th><b>Dead-letter queue (DLQ)</b> option</th><th>Do this...</th><th></th></tr>
</thead>
<tbody>
  <tr><td>Don't store</td><td>Choose <b>None</b>.</td><td></td></tr>
  <tr><td>Store the event in the same AWS account where you're creating the schedule</td><td> <ol><li> Choose <b>Select an Amazon SQS queue in my AWS account as a DLQ</b>. </li><li> Choose the Amazon Resource Name (ARN) of the Amazon SQS queue.  </li></ol> </td><td></td></tr>
  <tr><td>Store the event in a different AWS account from where you're creating the schedule</td><td> <ol><li> Choose <b>Specify an Amazon SQS queue in other AWS accounts as a DLQ</b>. </li><li> Enter the Amazon Resource Name (ARN) of the Amazon SQS queue.  </li></ol> </td><td></td></tr>
</tbody>
</table>


   1. To use a customer managed key to encrypt your target input, under **Encryption**, choose **Customize encryption settings (advanced)**. 

      If you choose this option, enter an existing KMS key ARN or choose **Create an AWS KMS key** to navigate to the AWS KMS console. For more information about how EventBridge Scheduler encrypts your data at rest, see [Encryption at rest](https://docs.aws.amazon.com/scheduler/latest/UserGuide/encryption-rest.html) in the *Amazon EventBridge Scheduler User Guide*. 

   1. For **Permissions**, choose **Use existing role**, then select the role.

      To have EventBridge Scheduler create a new execution role for you, choose **Create new role for this schedule**. Then, enter a name for **Role name**. If you choose this option, EventBridge Scheduler attaches the required permissions necessary for your templated target to the role. 

1. Choose **Next**. 

1.  In the **Review and create schedule** page, review the details of your schedule. In each section, choose **Edit** to go back to that step and edit its details. 

1. Choose **Create schedule**. 

   You can view a list of your new and existing schedules on the **Schedules** page. Under the **Status** column, verify that your new schedule is **Enabled**. 

## Next steps
<a name="eventbridge-scheduler-next-steps"></a>

You can use the EventBridge Scheduler console or the AWS CLI to manage the schedule. For more information, see [Managing a schedule](https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule.html) in the *Amazon EventBridge Scheduler User Guide*.