Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

Amazon CloudWatch Events Rule Target

The Target property type specifies a target, such as AWS Lambda (Lambda) functions or Kinesis streams, that CloudWatch Events invokes when a rule is triggered.

The Targets property of the AWS::Events::Rule resource contains a list of one or more Target property types.

Syntax

JSON

Copy
{ "Arn" : String, "EcsParameters" : EcsParameters, "Id" : String, "Input" : String, "InputPath" : String, "InputTransformer" : InputTransformer, "KinesisParameters" : KinesisParameters, "RoleArn" : String, "RunCommandParameters" : RunCommandParameters }

Properties

Note

For more information about each property, including constraints and valid values, see Amazon CloudWatch Events Rule Target in the Amazon CloudWatch Events API Reference.

Arn

The Amazon Resource Name (ARN) of the target.

Required: Yes

Type: String

EcsParameters

The Amazon ECS task definition and task count to use, if the event target is an Amazon ECS task.

Required: No

Type: CloudWatch Events Rule EcsParameters

Id

A unique, user-defined identifier for the target. Acceptable values include alphanumeric characters, periods (.), hyphens (-), and underscores (_).

Required: Yes

Type: String

Input

A JSON-formatted text string that is passed to the target. This value overrides the matched event.

Required: No. If you don't specify both this property and the InputPath property, CloudWatch Events passes the entire matched event to the target.

Type: String

InputPath

When you don't want to pass the entire matched event, the JSONPath that describes which part of the event to pass to the target.

Required: No. If you don't specify both this property and the Input property, CloudWatch Events passes the entire matched event to the target.

Type: String

InputTransformer

Settings that provide custom input to a target based on certain event data. You can extract one or more key-value pairs from the event, and then use that data to send customized input to the target.

Required: No

Type: CloudWatch Events Rule InputTransformer

KinesisParameters

Settings that control shard assignment, when the target is a Kinesis stream. If you don't include this parameter, eventId is used as the partition key.

Required: No

Type: CloudWatch Events Rule KinesisParameters

RoleArn

The Amazon Resource Name (ARN) of the AWS Identity and Access Management (IAM) role that grants CloudWatch Events permission to make calls to target services, such as AWS Lambda or Kinesis streams.

Required: No

Type: String

RunCommandParameters

Parameters used when the rule invokes Amazon EC2 Systems Manager Run Command.

Required: No

Type: CloudWatch Events Rule RunCommandParameters

Examples

The following examples define targets for an AWS::Events::Rule resource. For more examples, see PutTargets in the Amazon CloudWatch Events API Reference.

Target with KinesisParameters

The following snippet creates a Kinesis stream target.

JSON

Copy
"MyEventsRule": { "Type": "AWS::Events::Rule", "Properties": { "Description": "Events Rule with KinesisParameters", "EventPattern": { "source": [ "aws.ec2" ] }, "RoleArn": { "Fn::GetAtt": [ "EventsInvokeKinesisTargetRole", "Arn" ] }, "ScheduleExpression": "rate(5 minutes)", "State": "ENABLED", "Targets": [ { "Arn": { "Fn::GetAtt": [ "MyFirstStream", "Arn" ] }, "Id": "Id123", "RoleArn": { "Fn::GetAtt": [ "EventsInvokeKinesisTargetRole", "Arn" ] }, "KinesisParameters": { "PartitionKeyPath": "$" } } ] } }

YAML

Copy
MyEventsRule: Type: 'AWS::Events::Rule' Properties: Description: Events Rule with KinesisParameters EventPattern: source: - aws.ec2 RoleArn: !GetAtt - EventsInvokeKinesisTargetRole - Arn ScheduleExpression: rate(5 minutes) State: ENABLED Targets: - Arn: !GetAtt - MyFirstStream - Arn Id: Id123 RoleArn: !GetAtt - EventsInvokeKinesisTargetRole - Arn KinesisParameters: PartitionKeyPath: $

Target with EcsParameters

The following snippet creates an Amazon ECS task target.

JSON

Copy
"MyEventsRule": { "Type": "AWS::Events::Rule", "Properties": { "Description": "Events Rule with EcsParameters", "EventPattern": { "source": [ "aws.ec2" ], "detail-type": [ "EC2 Instance State-change Notification" ], "detail": { "state": [ "stopping" ] } }, "ScheduleExpression": "rate(15 minutes)", "State": "DISABLED", "Targets": [ { "Arn": { "Fn::GetAtt": [ "MyCluster", "Arn" ] }, "RoleArn": { "Fn::GetAtt": [ "ECSTaskRole", "Arn" ] }, "Id": "Id345", "EcsParameters": { "TaskCount": 1, "TaskDefinitionArn": { "Ref": "MyECSTask" } } } ] } }

YAML

Copy
MyEventsRule: Type: 'AWS::Events::Rule' Properties: Description: Events Rule with EcsParameters EventPattern: source: - aws.ec2 detail-type: - EC2 Instance State-change Notification detail: state: - stopping ScheduleExpression: rate(15 minutes) State: DISABLED Targets: - Arn: !GetAtt - MyCluster - Arn RoleArn: !GetAtt - ECSTaskRole - Arn Id: Id345 EcsParameters: TaskCount: 1 TaskDefinitionArn: !Ref MyECSTask

On this page: