See: Description
Interface | Description |
---|---|
ApiDestinationProps |
The event API Destination properties.
|
ArchiveProps |
The event archive properties.
|
BaseArchiveProps |
The event archive base properties.
|
CfnApiDestinationProps |
Properties for defining a `CfnApiDestination`.
|
CfnArchiveProps |
Properties for defining a `CfnArchive`.
|
CfnConnection.ApiKeyAuthParametersProperty |
Contains the API key authorization parameters for the connection.
|
CfnConnection.AuthParametersProperty |
Contains the authorization parameters to use for the connection.
|
CfnConnection.BasicAuthParametersProperty |
Contains the Basic authorization parameters for the connection.
|
CfnConnection.ClientParametersProperty |
Contains the OAuth authorization parameters to use for the connection.
|
CfnConnection.ConnectionHttpParametersProperty |
Contains additional parameters for the connection.
|
CfnConnection.OAuthParametersProperty |
Contains the OAuth authorization parameters to use for the connection.
|
CfnConnection.ParameterProperty |
Additional query string parameter for the connection.
|
CfnConnectionProps |
Properties for defining a `CfnConnection`.
|
CfnEndpoint.EndpointEventBusProperty |
The event buses the endpoint is associated with.
|
CfnEndpoint.FailoverConfigProperty |
The failover configuration for an endpoint.
|
CfnEndpoint.PrimaryProperty |
The primary Region of the endpoint.
|
CfnEndpoint.ReplicationConfigProperty |
Endpoints can replicate all events to the secondary Region.
|
CfnEndpoint.RoutingConfigProperty |
The routing configuration of the endpoint.
|
CfnEndpoint.SecondaryProperty |
The secondary Region that processes events when failover is triggered or replication is enabled.
|
CfnEndpointProps |
Properties for defining a `CfnEndpoint`.
|
CfnEventBus.TagEntryProperty |
A key-value pair associated with an AWS resource.
|
CfnEventBusPolicy.ConditionProperty |
A JSON string which you can use to limit the event bus permissions you are granting to only accounts that fulfill the condition.
|
CfnEventBusPolicyProps |
Properties for defining a `CfnEventBusPolicy`.
|
CfnEventBusProps |
Properties for defining a `CfnEventBus`.
|
CfnRule.AwsVpcConfigurationProperty |
This structure specifies the VPC subnets and security groups for the task, and whether a public IP address is to be used.
|
CfnRule.BatchArrayPropertiesProperty |
The array properties for the submitted job, such as the size of the array.
|
CfnRule.BatchParametersProperty |
The custom parameters to be used when the target is an AWS Batch job.
|
CfnRule.BatchRetryStrategyProperty |
The retry strategy to use for failed jobs, if the target is an AWS Batch job.
|
CfnRule.CapacityProviderStrategyItemProperty |
The details of a capacity provider strategy.
|
CfnRule.DeadLetterConfigProperty |
A `DeadLetterConfig` object that contains information about a dead-letter queue configuration.
|
CfnRule.EcsParametersProperty |
The custom parameters to be used when the target is an Amazon ECS task.
|
CfnRule.HttpParametersProperty |
These are custom parameter to be used when the target is an API Gateway REST APIs or EventBridge ApiDestinations.
|
CfnRule.InputTransformerProperty |
Contains the parameters needed for you to provide custom input to a target based on one or more pieces of data extracted from the event.
|
CfnRule.KinesisParametersProperty |
This object enables you to specify a JSON path to extract from the event and use as the partition key for the Amazon Kinesis data stream, so that you can control the shard to which the event goes.
|
CfnRule.NetworkConfigurationProperty |
This structure specifies the network configuration for an ECS task.
|
CfnRule.PlacementConstraintProperty |
An object representing a constraint on task placement.
|
CfnRule.PlacementStrategyProperty |
The task placement strategy for a task or service.
|
CfnRule.RedshiftDataParametersProperty |
These are custom parameters to be used when the target is a Amazon Redshift cluster to invoke the Amazon Redshift Data API ExecuteStatement based on EventBridge events.
|
CfnRule.RetryPolicyProperty |
A `RetryPolicy` object that includes information about the retry policy settings.
|
CfnRule.RunCommandParametersProperty |
This parameter contains the criteria (either InstanceIds or a tag) used to specify which EC2 instances are to be sent the command.
|
CfnRule.RunCommandTargetProperty |
Information about the EC2 instances that are to be sent the command, specified as key-value pairs.
|
CfnRule.SageMakerPipelineParameterProperty |
Name/Value pair of a parameter to start execution of a SageMaker Model Building Pipeline.
|
CfnRule.SageMakerPipelineParametersProperty |
These are custom parameters to use when the target is a SageMaker Model Building Pipeline that starts based on EventBridge events.
|
CfnRule.SqsParametersProperty |
This structure includes the custom parameter to be used when the target is an SQS FIFO queue.
|
CfnRule.TagProperty |
A key-value pair associated with an ECS Target of an EventBridge rule.
|
CfnRule.TargetProperty |
Targets are the resources to be invoked when a rule is triggered.
|
CfnRuleProps |
Properties for defining a `CfnRule`.
|
ConnectionAttributes |
Interface with properties necessary to import a reusable Connection.
|
ConnectionProps |
An API Destination Connection.
|
CronOptions |
Options to configure a cron expression.
|
EventBusAttributes |
Interface with properties necessary to import a reusable EventBus.
|
EventBusProps |
Properties to define an event bus.
|
EventPattern |
Events in Amazon CloudWatch Events are represented as JSON objects.
|
IApiDestination |
Interface for API Destinations.
|
IApiDestination.Jsii$Default |
Internal default implementation for
IApiDestination . |
IConnection |
Interface for EventBus Connections.
|
IConnection.Jsii$Default |
Internal default implementation for
IConnection . |
IEventBus |
Interface which all EventBus based classes MUST implement.
|
IEventBus.Jsii$Default |
Internal default implementation for
IEventBus . |
IRule |
Represents an EventBridge Rule.
|
IRule.Jsii$Default |
Internal default implementation for
IRule . |
IRuleTarget |
An abstract target for EventRules.
|
IRuleTarget.Jsii$Default |
Internal default implementation for
IRuleTarget . |
OAuthAuthorizationProps |
Properties for `Authorization.oauth()`.
|
OnEventOptions |
Standard set of options for `onXxx` event handlers on construct.
|
RuleProps |
Properties for defining an EventBridge Rule.
|
RuleTargetConfig |
Properties for an event rule target.
|
RuleTargetInputProperties |
The input properties for an event target.
|
Enum | Description |
---|---|
HttpMethod |
Supported HTTP operations.
|
---
Amazon EventBridge 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 its state.
The Rule
construct defines an EventBridge 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:
Repository repo; Project project; Rule onCommitRule = repo.onCommit("OnCommit", OnCommitOptions.builder() .target(new CodeBuildProject(project)) .branches(List.of("master")) .build());
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:
Rule onCommitRule; Topic topic; onCommitRule.addTarget(SnsTopic.Builder.create(topic) .message(RuleTargetInput.fromText(String.format("A commit was pushed to the repository %s on branch %s", ReferenceEvent.getRepositoryName(), ReferenceEvent.getReferenceName()))) .build());
Or using an Object:
Rule onCommitRule; Topic topic; onCommitRule.addTarget(SnsTopic.Builder.create(topic) .message(RuleTargetInput.fromObject(Map.of( "DataType", String.format("custom_%s", EventField.fromPath("$.detail-type"))))) .build());
You can configure a Rule to run on a schedule (cron or rate). Rate must be specified in minutes, hours or days.
The following example runs a task every day at 4am:
import software.amazon.awscdk.services.events.Rule; import software.amazon.awscdk.services.events.Schedule; import software.amazon.awscdk.services.events.targets.EcsTask; import software.amazon.awscdk.services.ecs.Cluster; import software.amazon.awscdk.services.ecs.TaskDefinition; import software.amazon.awscdk.services.iam.Role; Cluster cluster; TaskDefinition taskDefinition; Role role; EcsTask ecsTaskTarget = EcsTask.Builder.create().cluster(cluster).taskDefinition(taskDefinition).role(role).build(); Rule.Builder.create(this, "ScheduleRule") .schedule(Schedule.cron(CronOptions.builder().minute("0").hour("4").build())) .targets(List.of(ecsTaskTarget)) .build();
If you want to specify Fargate platform version, set platformVersion
in EcsTask's props like the following example:
Cluster cluster; TaskDefinition taskDefinition; Role role; FargatePlatformVersion platformVersion = FargatePlatformVersion.VERSION1_4; EcsTask ecsTaskTarget = EcsTask.Builder.create().cluster(cluster).taskDefinition(taskDefinition).role(role).platformVersion(platformVersion).build();
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.BatchJob
: Queue an AWS Batch Jobtargets.AwsApi
: Make an AWS API calltargets.ApiGateway
: Invoke an AWS API Gatewaytargets.ApiDestination
: Make an call to an external destination
It's possible to have the source of the event and a target in separate AWS accounts and regions:
import software.amazon.awscdk.core.App; import software.amazon.awscdk.core.Stack; import software.amazon.awscdk.services.codebuild.*; import software.amazon.awscdk.services.codecommit.*; import software.amazon.awscdk.services.events.targets.*; App app = new App(); String account1 = "11111111111"; String account2 = "22222222222"; Stack stack1 = Stack.Builder.create(app, "Stack1").env(Environment.builder().account(account1).region("us-west-1").build()).build(); Repository repo = Repository.Builder.create(stack1, "Repository") .repositoryName("myrepository") .build(); Stack stack2 = Stack.Builder.create(app, "Stack2").env(Environment.builder().account(account2).region("us-east-1").build()).build(); Project project = Project.Builder.create(stack2, "Project").build(); repo.onCommit("OnCommit", OnCommitOptions.builder() .target(new CodeBuildProject(project)) .build());
In this situation, the CDK will wire the 2 accounts together:
For more information, see the AWS documentation on cross-account events.
It is possible to archive all or some events sent to an event bus. It is then possible to replay these events.
EventBus bus = EventBus.Builder.create(this, "bus") .eventBusName("MyCustomEventBus") .build(); bus.archive("MyArchive", BaseArchiveProps.builder() .archiveName("MyCustomEventBusArchive") .description("MyCustomerEventBus Archive") .eventPattern(EventPattern.builder() .account(List.of(Stack.of(this).getAccount())) .build()) .retention(Duration.days(365)) .build());
To import an existing EventBus into your CDK application, use EventBus.fromEventBusArn
, EventBus.fromEventBusAttributes
or EventBus.fromEventBusName
factory method.
Then, you can use the grantPutEventsTo
method to grant event:PutEvents
to the eventBus.
Function lambdaFunction; IEventBus eventBus = EventBus.fromEventBusArn(this, "ImportedEventBus", "arn:aws:events:us-east-1:111111111:event-bus/my-event-bus"); // now you can just call methods on the eventbus eventBus.grantPutEventsTo(lambdaFunction);