Skip to content

Commit

Permalink
Update README.md (aws#5310)
Browse files Browse the repository at this point in the history
Adding information about Rule scheduling (cron) with a simple example
  • Loading branch information
IsmaelMartinez authored and mergify[bot] committed Dec 8, 2019
1 parent 891ef5f commit 72b6989
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ event when the pipeline changes it's state.
or it can receive events from applications and services created by AWS SaaS partners.
See [Creating an Event Bus](https://docs.aws.amazon.com/eventbridge/latest/userguide/create-event-bus.html).

## Rule

The `Rule` construct defines a CloudWatch events rule which monitors an
event based on an [event
pattern](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEventsandEventPatterns.html)
Expand Down Expand Up @@ -76,6 +78,27 @@ onCommitRule.addTarget(new targets.SnsTopic(topic, {
}));
```

## Scheduling

You can configure a Rule to run on a schedule (cron or rate).

The following example runs a task every day at 4am:

```ts
import { Rule, Schedule } from '@aws-cdk/aws-events';
import { EcsTask } from '@aws-cdk/aws-events-targets';
...

const ecsTaskTarget = new EcsTask({ cluster, taskDefinition });

new Rule(this, 'ScheduleRule', {
schedule: Schedule.cron({ minute: '0', hour: '4' }),
targets: [ecsTaskTarget],
});
```

More details in [ScheduledEvents](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html) documentation page.

## Event Targets

The `@aws-cdk/aws-events-targets` module includes classes that implement the `IRuleTarget`
Expand Down

0 comments on commit 72b6989

Please sign in to comment.