
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@aws-cdk/aws-events
Advanced tools
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 IRuleTarget
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('OnCommit', {
target: new targets.CodeBuildProject(project),
branches: ['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(new targets.SnsTopic(topic, {
message: events.RuleTargetInput.fromText(
`A commit was pushed to the repository ${codecommit.ReferenceEvent.repositoryName} on branch ${codecommit.ReferenceEvent.referenceName}`
)
}));
The @aws-cdk/aws-events-targets
module includes classes that implement the IRuleTarget
interface for various AWS services.
The following targets are supported:
targets.CodeBuildProject
: Start an AWS CodeBuild buildtargets.CodePipeline
: Start an AWS CodePipeline pipeline executiontargets.EcsTask
: Start a task on an Amazon ECS clustertargets.LambdaFunction
: Invoke an AWS Lambda functiontargets.SnsTopic
: Publish into an SNS topictargets.SqsQueue
: Send a message to an Amazon SQS Queuetargets.SfnStateMachine
: Trigger an AWS Step Functions state machinetargets.AwsApi
: Make an AWS API callIt's possible to have the source of the event and a target in separate AWS accounts:
import { App, Stack } from '@aws-cdk/core';
import codebuild = require('@aws-cdk/aws-codebuild');
import codecommit = require('@aws-cdk/aws-codecommit');
import targets = require('@aws-cdk/aws-events-targets');
const app = new App();
const stack1 = new Stack(app, 'Stack1', { env: { account: account1, region: 'us-east-1' } });
const repo = new codecommit.Repository(stack1, 'Repository', {
// ...
});
const stack2 = new Stack(app, 'Stack2', { env: { account: account2, region: 'us-east-1' } });
const project = new codebuild.Project(stack2, 'Project', {
// ...
});
repo.onCommit('OnCommit', {
target: new targets.CodeBuildProject(project),
});
In this situation, the CDK will wire the 2 accounts together:
Note: while events can span multiple accounts, they cannot span different regions (that is a CloudWatch, not CDK, limitation).
For more information, see the AWS documentation on cross-account events.
FAQs
Amazon EventBridge Construct Library
We found that @aws-cdk/aws-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.