|
| 1 | +--- |
| 2 | +title: "EventBridge Scheduler" |
| 3 | +linkTitle: "EventBridge Scheduler" |
| 4 | +description: Get started with EventBridge Scheduler on LocalStack |
| 5 | +--- |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +EventBridge Scheduler is a service that enables you to schedule the execution of your AWS Lambda functions, Amazon ECS tasks, and Amazon Batch jobs. You can use EventBridge Scheduler to create schedules that run at a specific time or at regular intervals. You can also use EventBridge Scheduler to create schedules that run within a flexible time window. |
| 10 | + |
| 11 | +LocalStack allows you to use the Scheduler APIs in your local environment to create and run schedules. The supported APIs are available on our [API coverage page](https://docs.localstack.cloud/references/coverage/coverage_scheduler/), which provides information on the extent of EventBridge Scheduler's integration with LocalStack. |
| 12 | + |
| 13 | +## Getting started |
| 14 | + |
| 15 | +This guide is designed for users new to EventBridge Scheduler and assumes basic knowledge of the AWS CLI and our [`awslocal`](https://github.com/localstack/awscli-local) wrapper script. |
| 16 | + |
| 17 | +Start your LocalStack container using your preferred method. We will demonstrate how you can create a new schedule, list all schedules, and tag a schedule using the EventBridge Scheduler APIs. |
| 18 | + |
| 19 | +### Create a new SQS queue |
| 20 | + |
| 21 | +You can create a new SQS queue using the [`CreateQueue`](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_CreateQueue.html) API. Run the following command to create a new SQS queue: |
| 22 | + |
| 23 | +{{< command >}} |
| 24 | +$ awslocal sqs create-queue --queue-name local-notifications |
| 25 | +{{< /command >}} |
| 26 | + |
| 27 | +You can fetch the Queue ARN using the [`GetQueueAttributes`](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueAttributes.html) API. Run the following command to fetch the Queue ARN by specifying the Queue URL: |
| 28 | + |
| 29 | +{{< command >}} |
| 30 | +$ awslocal sqs get-queue-attributes \ |
| 31 | + --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/local-notifications \ |
| 32 | + --attribute-names All |
| 33 | +{{< /command >}} |
| 34 | + |
| 35 | +Save the Queue ARN for later use. |
| 36 | + |
| 37 | +### Create a new schedule |
| 38 | + |
| 39 | +You can create a new schedule using the [`CreateSchedule`](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_CreateSchedule.html) API. Run the following command to create a new schedule: |
| 40 | + |
| 41 | +{{< command >}} |
| 42 | +$ awslocal scheduler create-schedule \ |
| 43 | + --name sqs-templated-schedule \ |
| 44 | + --schedule-expression 'rate(5 minutes)' \ |
| 45 | + --target '{"RoleArn": "arn:aws:iam::000000000000:role/schedule-role", "Arn":"arn:aws:sqs:us-east-1:000000000000:local-notifications", "Input": "test" }' \ |
| 46 | + --flexible-time-window '{ "Mode": "OFF"}' |
| 47 | +{{< /command >}} |
| 48 | + |
| 49 | +The following output is displayed: |
| 50 | + |
| 51 | +```bash |
| 52 | +{ |
| 53 | + "ScheduleArn": "arn:aws:scheduler:us-east-1:000000000000:schedule/default/sqs-templated-schedule" |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### List all schedules |
| 58 | + |
| 59 | +You can list all schedules using the [`ListSchedules`](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_ListSchedules.html) API. Run the following command to list all schedules: |
| 60 | + |
| 61 | +{{< command >}} |
| 62 | +$ awslocal scheduler list-schedules |
| 63 | +{{< /command >}} |
| 64 | + |
| 65 | +The following output is displayed: |
| 66 | + |
| 67 | +```bash |
| 68 | +{ |
| 69 | + "Schedules": [ |
| 70 | + { |
| 71 | + "Arn": "arn:aws:scheduler:us-east-1:000000000000:schedule/default/sqs-templated-schedule", |
| 72 | + "CreationDate": "2024-07-11T23:13:15.296906+05:30", |
| 73 | + "GroupName": "default", |
| 74 | + "LastModificationDate": "2024-07-11T23:13:15.296906+05:30", |
| 75 | + "Name": "sqs-templated-schedule", |
| 76 | + "State": "ENABLED", |
| 77 | + "Target": { |
| 78 | + "Arn": "arn:aws:sqs:us-east-1:000000000000:local-notifications" |
| 79 | + } |
| 80 | + } |
| 81 | + ] |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### Tag a schedule |
| 86 | + |
| 87 | +You can tag a schedule using the [`TagResource`](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_TagResource.html) API. Run the following command to tag a schedule: |
| 88 | + |
| 89 | +{{< command >}} |
| 90 | +$ awslocal scheduler tag-resource \ |
| 91 | + --resource-arn arn:aws:scheduler:us-east-1:000000000000:schedule/default/sqs-templated-schedule \ |
| 92 | + --tags Key=Name,Value=Test |
| 93 | +{{< /command >}} |
0 commit comments