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
{ "Arn" :String, "EcsParameters" : EcsParameters, "Id" :String, "Input" :String, "InputPath" :String, "InputTransformer" : InputTransformer, "KinesisParameters" : KinesisParameters, "RoleArn" :String, "RunCommandParameters" : RunCommandParameters }
YAML
Arn:StringEcsParameters: EcsParameters Id:StringInput:StringInputPath:StringInputTransformer: InputTransformer KinesisParameters: KinesisParameters RoleArn:StringRunCommandParameters: 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: 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
InputPathproperty, 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
Inputproperty, 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: InputTransformer
KinesisParameters-
Settings that control shard assignment, when the target is a Kinesis stream. If you don't include this parameter,
eventIdis used as the partition key.Required: No
Type: KinesisParameters
RoleArn-
The Amazon Resource Name (ARN) of the AWS Identity and Access Management (IAM) role to use for this target when the rule is triggered. If one rule triggers multiple targets, you can use a different IAM role for each target.
Note
CloudWatch Events needs appropriate permissions to make API calls against the resources you own. For Kinesis streams, CloudWatch Events relies on IAM roles. For Lambda, Amazon SNS, and Amazon SQS resources, CloudWatch Events relies on resource-based policies. For more information, see Using Resource-Based Policies for CloudWatch Events in the Amazon CloudWatch User Guide.
Required: No
Type: String
RunCommandParameters-
Parameters used when the rule invokes the AWS Systems Manager Run Command.
Required: No
Type: 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
"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
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
"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
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
