

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon 中的事件总线目标 EventBridge
<a name="eb-targets"></a>

*目标*是一种资源或端点，当[事件](eb-events.md)与为[规则](eb-rules.md)定义的事件模式匹配时，它会向其 EventBridge 发送事件。**规则会处理[事件](eb-events.md)数据，并将相关信息发送给目标。要将事件数据传送到目标， EventBridge 需要访问目标资源的权限。您最多可以为每条规则定义五个目标。

当您将目标添加到规则，之后该规则很快运行，可能不会立即调用新的或更新的目标。请稍等片刻，以便更改生效。

## EventBridge 控制台中提供事件总线目标
<a name="eb-console-targets"></a>

您可以在 EventBridge 控制台中为规则配置以下目标类型：
+ API 目标

  API 目标属于 HTTPS 端点，您可以将其作为事件总线规则的目标进行调用。当您将 API 目标指定为规则目标时，会为任何与规则中指定的事件模式匹配的事件 EventBridge 调用 HTTPS 终端节点，然后随请求传送事件信息。有关更多信息，请参阅 [API 目标](eb-api-destinations.md)。
+ 事件总线

  您可以将其他事件总线指定为规则的目标。这包括相同或不同 Amazon 账户中的事件总线。
  + [作为目标的跨账户事件总线](eb-cross-account.md)
  + [作为目标的同账户事件总线](eb-bus-to-bus.md)
+ Amazon 服务

  您可以将事件 EventBridge 发送到多个 Amazon 服务资源。这些方法包括：
  + [API Gateway](eb-api-gateway-target.md)
  + [Amazon AppSync](target-appsync.md)
  + [批处理作业队列](#targets-specifics-batch)
  + [CloudWatch 日志组](#targets-specifics-cwl)
  + [CodeBuild 项目](#targets-specifics-codebuild)
  + CodePipeline
  + Amazon EBS `CreateSnapshot` API 调用
  + EC2 Image Builder
  + EC2 `RebootInstances` API 调用
  + EC2 `StopInstances` API 调用
  + EC2 `TerminateInstances` API 调用
  + [ECS 任务](#targets-specifics-ecs-task)
  + Firehose 传输流
  + Glue 工作流
  + [Incident Manager 响应计划](https://docs.amazonaws.cn//incident-manager/latest/userguide/incident-creation.html#incident-tracking-auto-eventbridge)
  + Inspector 评估模板
  + Kinesis 流
  + Lambda 函数（异步）
  + [Amazon Redshift 集群数据 API 查询](https://docs.amazonaws.cn/redshift/latest/mgmt/data-api-calling-event-bridge.html) 
  + [Amazon Redshift Serverless 工作组数据 API 查询](https://docs.amazonaws.cn/redshift/latest/mgmt/data-api-calling-event-bridge.html)
  + SageMaker AI 管道
  + 亚马逊 SNS 主题
  + [亚马逊 SQS 标准队列、公平队列和 FIFO 队列](#targets-specifics-sqs)
  + Step Functions 状态机（异步）
  + Systems Manager Automation
  + Systems Manager OpsItem
  + Systems Manager 运行命令

## 目标参数
<a name="targets-specific-parms"></a>

有些目标不会将事件负载中的信息发送给目标，而是将事件视为调用特定 API 的触发器。 EventBridge 使用 Targe [t](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_Target.html) 参数来确定该目标会发生什么。这些功能包括：
+ API 目标

  发送到 API 目标的数据必须与 API 的结构相匹配。使用 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html) 对象可确保数据结构正确无误。如果要包含原始事件有效载荷，请在 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html) 中引用它。
+ API Gateway 

  发送到 API Gateway 的数据必须与 API 的结构相匹配。使用 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html) 对象可确保数据结构正确无误。如果要包含原始事件有效载荷，请在 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html) 中引用它。
+ Amazon EC2 Image Builder
+ Amazon Redshift 数据 API 集群

  使用 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RedshiftDataParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RedshiftDataParameters.html)。
+ Amazon SageMaker 运行时模型构建管道

  使用 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html)。
+ 亚马逊 SQS 博览会和 FIFO 队列

  使用 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SqsParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SqsParameters.html) 指定要用作目标的消息组。
+ Systems Manager 运行命令

  用于[https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RunCommandParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RunCommandParameters.html)指定 SSM 文档和目标实例。有关更多信息，请参阅 [Systems Manager 以目标方式运行命令](#targets-specifics-ssm-run-command)。

**注意**  
EventBridge 不支持所有 JSON 路径语法并在运行时对其进行评估。支持的语法包括：  
点表示法（例如 `$.detail`）
短划线
下划线
字母数字字符
数组索引
通配符 (\$1)
向前斜杠

### 动态路径参数
<a name="dynamic-path-parameters"></a>

动态路径参数允许您在运行时使用 JSON 路径语法来引用事件数据，而不是静态值。

您可以使用带有目标参数的动态 JSON 路径语法来指定 JSON 路径而不是静态值（例如`$.detail.state`）。

#### 要求
<a name="requirements"></a>

整个值必须是 JSON 路径，而不仅仅是其中的一部分。例如：
+ ✓ 正确：`RedshiftParameters.Sql`可以 `$.detail.state`
+ ✗ 不正确：`RedshiftParameters.Sql`不能 `"SELECT * FROM $.detail.state"`

EventBridge 在运行时将这些路径替换为来自指定路径的事件负载的数据。

#### 限制
<a name="limitations"></a>

动态路径参数不能引用输入转换中的新值或转换后的值。JSON 路径语法与输入转换语法相同。有关更多信息，请参阅 [Amazon EventBridge 输入转换](eb-transform-target-input.md)。

#### 支持的参数
<a name="supported-parameters"></a>

你可以对这些参数的所有字符串、非枚举字段使用动态语法：
+ [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_EcsParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_EcsParameters.html)
+ [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_HttpParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_HttpParameters.html)（`HeaderParameters` 键除外）
+ [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RedshiftDataParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RedshiftDataParameters.html)
+ [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html)
+ [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SqsParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_SqsParameters.html)

## Permissions
<a name="targets-permissions"></a>

要对您拥有的资源进行 API 调用， EventBridge 需要适当的权限。[使用 EventBridge控制台或通过在中](eb-create-rule-wizard.md#eb-create-rule-target)设置`RoleARN`参数来指定 IAM 执行角色[https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_PutTargets.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_PutTargets.html)。

例如，以下策略定义了向 Amazon SQS 队列发送消息的权限：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sqs:SendMessage"
            ],
            "Resource": [
                "arn:aws:sqs:us-east-1:111122223333:sqs-queue-name"
            ]
        }
    ]
}
```

------

以下信任策略允许代 EventBridge 入该角色：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "events.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

------

您可以使用已配置的 IAM 授权调用 API Gateway 端点，但如果您尚未配置授权，该角色是可选的。有关更多信息，请参阅 [亚马逊 EventBridge 和 Amazon Identity and Access Management](eb-iam.md)。

如果另一账户在同一区域中，并且已授予您权限，您可以向该账户发送事件。

有关更多信息，请参阅 [在 Amazon Amazon 账户之间发送和接收事件 EventBridge](eb-cross-account.md)。

如果您的目标（例如 Amazon SQS 队列）使用 Amazon Key Management Service (Amazon KMS) 加密，则必须在 KMS 密钥策略中包含以下部分：

```
{
  "Sid": "Allow EventBridge to use the key",
  "Effect": "Allow",
  "Principal": {
    "Service": "events.amazonaws.com"
  },
  "Action": [
    "kms:Decrypt",
    "kms:GenerateDataKey"
  ],
  "Resource": "*"
}
```

## Amazon Batch 任务队列作为目标
<a name="targets-specifics-batch"></a>

某些参数 Amazon Batch `submitJob`可以通过进行配置[BatchParameters](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_BatchParameters.html)。

其他参数可以在事件负载中指定。如果事件负载（通过或通过 [InputTransformers](https://docs.amazonaws.cn/eventbridge/latest/userguide/eb-transform-target-input.html)）包含以下密钥，则它们将被映射到`submitJob`[请求参数](https://docs.amazonaws.cn/batch/latest/APIReference/API_SubmitJob.html#API_SubmitJob_RequestSyntax)：
+ `ContainerOverrides: containerOverrides`
**注意**  
仅包括命令、环境、内存和 vCPU
+ `DependsOn: dependsOn`
**注意**  
仅包括 jobId
+ `Parameters: parameters`

## CloudWatch 将组记录为目标
<a name="targets-specifics-cwl"></a>

如果您不使用[InputTransformer](https://docs.amazonaws.cn/eventbridge/latest/userguide/eb-transform-target-input.html)带有 CloudWatch Logs 目标的，则事件负载将用作日志消息，将事件的源用作时间戳。如果您确实使用了 InputTransformer，则模板必须是：

`{"timestamp":<timestamp>,"message":<message>}`

EventBridge 对发送到日志流的条目进行批处理；因此， EventBridge 可能会将单个或多个事件传送到日志流，具体取决于流量。

## CodeBuild 以项目为目标
<a name="targets-specifics-codebuild"></a>

EventBridge 支持将标准版和批量版作为目标。

如果在将源事件传送到 CodeBuild 目标之前，使用[输入转换器](https://docs.amazonaws.cn/eventbridge/latest/userguide/eb-transform-target-input.html)对源事件进行整形以匹配[StartBuildRequest](https://docs.amazonaws.cn/codebuild/latest/APIReference/API_StartBuild.html#API_StartBuild_RequestSyntax)结构，则默认情况下，参数将以 1 比 1 的比`codeBuild.StartBuild`分映射并传递到。

要`codeBuild.StartBuildBatch`改为将参数传递给，请转换源事件以匹配[StartBuildBatchRequest](https://docs.amazonaws.cn/codebuild/latest/APIReference/API_StartBuildBatch.html#API_StartBuildBatch_RequestSyntax)结构，然后将以下 key/value 一对添加到已转换事件的根中：

`"buildType": "BATCH"`

## 作为目标的 Amazon ECS 任务
<a name="targets-specifics-ecs-task"></a>

如果您使用[InputTransformers](https://docs.amazonaws.cn/eventbridge/latest/userguide/eb-transform-target-input.html)将输入事件塑造成目标以匹配 Amazon ECS RunTask [TaskOverride](https://docs.amazonaws.cn/AmazonECS/latest/APIReference/API_TaskOverride.html)结构，则参数将以 1 比 1 的比分映射并传递到。`ecs.RunTask`

## 作为目标的 Incident Manager 响应计划
<a name="targets-specifics-incident-manager"></a>

如果匹配的事件来自 CloudWatch 警报，则警报状态更改详细信息将填充到事件管理器 StartIncidentRequest 呼叫的触发器详细信息中。

## Systems Manager 将命令作为目标运行
<a name="targets-specifics-ssm-run-command"></a>

当你将 Systems Manager Run Command 指定为目标时，会代表你 EventBridge 调用 [https://docs.amazonaws.cn/systems-manager/latest/APIReference/API_SendCommand.html](https://docs.amazonaws.cn/systems-manager/latest/APIReference/API_SendCommand.html)API。使用配置目标 [https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RunCommandParameters.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_RunCommandParameters.html)，它指定要运行的 SSM 文档以及目标实例或标签。

`RunCommandParameters`包含以下字段：
+ `RunCommandTargets`—（必需）指定目标实例的键值对列表。`Key`将 set to 用于实例列表 IDs，或者将`Key`设置为 w `tag:tag-name` ith 标签值按标签来定位实例。`InstanceIds`您可以指定 1 到 5 个运行命令目标。

要指定要运行的 SSM 文档并向其传递参数，请使用[https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_Target.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_Target.html)对象上的`Input`字段。该`Input`值必须是具有以下结构的 JSON 对象：

```
{
  "DocumentName": "document-name",
  "DocumentVersion": "version",
  "Parameters": {
    "parameter-key": ["parameter-value"]
  }
}
```

其中：
+ `DocumentName`— 要运行的 SSM 文档的名称或 ARN。
+ `DocumentVersion`—（可选）文档的版本。如果省略，则使用默认版本。
+ `Parameters`—（可选）参数名称到值数组的映射，与 SSM 文档中定义的参数相匹配。

例如，以下 Amazon CLI 命令创建一条规则，当 EventBridge 事件匹配时，该规则会在特定实例上运行`AWS-RunShellScript`文档：

```
aws events put-targets --rule "my-rule" --targets '[{
  "Id": "ssm-target-1",
  "Arn": "arn:aws:ssm:region:account-id:document/AWS-RunShellScript",
  "RoleArn": "arn:aws:iam::account-id:role/EventBridgeSSMRole",
  "Input": "{\\"Parameters\\":{\\"commands\\":[\\"echo Hello from EventBridge\\"]}}",
  "RunCommandParameters": {
    "RunCommandTargets": [{
      "Key": "InstanceIds",
      "Values": ["i-0123456789abcdef0"]
    }]
  }
}]'
```

**注意**  
`Target`对象上的`Input`字段用于将文档名称和参数传递给 Systems Manager 运行命令。这与转换事件负载的不同。[https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.amazonaws.cn/eventbridge/latest/APIReference/API_InputTransformer.html)使用 Systems Manager 运行命令作为目标时，请在中设置文档参数`Input`并在中指定目标实例`RunCommandParameters`。

## 作为目标的 Amazon SQS 队列
<a name="targets-specifics-sqs"></a>

EventBridge 不支持使用使用加密的 Amazon SQS 队列。 Amazon 拥有的密钥这包括目标，以及指定为目标死信队列的 Amazon SQS 队列。有关更多信息 Amazon 拥有的密钥，请参阅《*Amazon Key Management Service 开发者指南》*中的[Amazon 自有密钥](https://docs.amazonaws.cn/kms/latest/developerguide/concepts.html#aws-owned-cmk)。