Skip navigation links

@Stability(value=Experimental)

Package software.amazon.awscdk.services.events

Amazon CloudWatch Events Construct Library

See: Description

Package software.amazon.awscdk.services.events Description

Amazon CloudWatch Events Construct Library


Stability: Experimental

This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.


Amazon CloudWatch Events delivers a near real-time stream of system events that describe changes in AWS resources. For example, an AWS CodePipeline emits the State Change event when the pipeline changes it's state.

The Rule construct defines a CloudWatch events rule which monitors an event based on an event pattern and invoke event targets when the pattern is matched against a triggered event. Event targets are objects that implement the IEventTarget interface.

Normally, you will use one of the source.onXxx(name[, target[, options]]) -> Rule methods on the event source to define an event rule associated with the specific activity. You can targets either via props, or add targets using rule.addTarget.

For example, to define an rule that triggers a CodeBuild project build when a commit is pushed to the "master" branch of a CodeCommit repository:

const onCommitRule = repo.onCommit('OnCommitToMaster', project, 'master');
 

You can add additional targets, with optional input transformer using eventRule.addTarget(target[, input]). For example, we can add a SNS topic target which formats a human-readable message for the commit.

For example, this adds an SNS topic as a target:

onCommitRule.addTarget(topic, {
     template: 'A commit was pushed to the repository <repo> on branch <branch>',
     pathsMap: {
         branch: '$.detail.referenceName',
         repo: '$.detail.repositoryName'
     }
 });
 

Event Targets

The @aws-cdk/aws-events-targets module includes classes that implement the IRuleTarget interface for various AWS services.

The following targets are supported:

Skip navigation links

Copyright © 2019. All rights reserved.