

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon EventBridge 中的事件匯流排目標
<a name="eb-targets"></a>

*目標*是指當事件符合為[規則](eb-rules.md)定義的事件模式時，EventBridge 會傳送[事件](eb-events.md)的資源或端點。**規則會處理[事件](eb-events.md)資料，並將相關資訊傳送至目標。若要將事件資料交付至目標，EventBridge 需要存取目標資源的許可。您最多可以為每個規則定義五個目標。

當您將目標新增至規則且該規則不久會運行時，可能不會立即調用任何新的目標或更新的目標。允許一小段時間來讓變更生效。

## EventBridge 主控台中可用的事件匯流排目標
<a name="eb-console-targets"></a>

您可以在 EventBridge 主控台中為規則設定下列目標類型：
+ API 目的地

  API 目的地是 HTTPS 端點，您可以呼叫它做為事件匯流排規則的目標。當您將 API 目的地指定為規則目標時，EventBridge 會針對符合規則中指定事件模式的任何事件叫用 HTTPS 端點，然後隨 請求傳遞事件資訊。如需詳細資訊，請參閱[API 目的地](eb-api-destinations.md)。
+ 事件匯流排

  您可以指定其他事件匯流排做為規則的目標。這包括相同或不同 AWS 帳戶中的事件匯流排。
  + [以跨帳戶事件匯流排做為目標](eb-cross-account.md)
  + [與目標相同的帳戶事件匯流排](eb-bus-to-bus.md)
+ AWS 服務

  您可以讓 EventBridge 將事件傳送到許多 AWS 服務資源。其中包含：
  + [API Gateway](eb-api-gateway-target.md)
  + [AWS 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 工作流程
  + [Indent Manager 回應計劃](https://docs.aws.amazon.com//incident-manager/latest/userguide/incident-creation.html#incident-tracking-auto-eventbridge)
  + Inspector 評估範本
  + Kinesis 串流
  + Lambda 函數 (ASYNC)
  + [Amazon Redshift 叢集資料 API 查詢](https://docs.aws.amazon.com/redshift/latest/mgmt/data-api-calling-event-bridge.html) 
  + [Amazon Redshift Serverless 工作群組資料 API 查詢](https://docs.aws.amazon.com/redshift/latest/mgmt/data-api-calling-event-bridge.html)
  + SageMaker AI 管道
  + Amazon SNS 主題
  + [Amazon SQS 標準、公平和 FIFO 佇列](#targets-specifics-sqs)
  + Step Functions 狀態機器 (ASYNC)
  + Systems Manager Automation
  + Systems Manager OpsItem
  + Systems Manager Run Command

## 目標參數
<a name="targets-specific-parms"></a>

有些目標不會將事件裝載中的資訊傳送至目標，而是將事件視為調用特定 API 的觸發器。EventBridge 使用[目標](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_Target.html)參數來決定該目標會發生什麼情況。這些索引標籤包括以下項目：
+ API 目的地

  傳送至 API 目的地的資料必須符合 API 的結構。使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html) 物件來確保資料結構正確。如果您想要包含原始事件承載，請在 中參考它[https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html)。
+ API Gateway 

  傳送至 API Gateway 的資料必須符合 API 的結構。使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html) 物件來確保資料結構正確。如果您想要包含原始事件承載，請在 中參考它[https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html)。
+ Amazon EC2 Image Builder
+ Amazon Redshift Data API 叢集

  請使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RedshiftDataParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RedshiftDataParameters.html)。
+ Amazon SageMaker 執行期模型建置管道

  請使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html)。
+ Amazon SQS 公平佇列和 FIFO 佇列

  使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SqsParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SqsParameters.html)指定要用作目標的訊息群組。
+ Systems Manager Run Command

  使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RunCommandParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RunCommandParameters.html)指定 SSM 文件和目標執行個體。如需詳細資訊，請參閱 [Systems Manager Run Command 做為目標](#targets-specifics-ssm-run-command)。

**注意**  
EventBridge 不支援所有 JSON 路徑語法，並在執行期對其進行評估。支援的語法包括：  
點符號 (例如 `$.detail`)
破折號
底線
英數字元
陣列索引
萬用字元 (\*)
正斜線

### 動態路徑參數
<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.aws.amazon.com/eventbridge/latest/APIReference/API_EcsParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_EcsParameters.html)
+ [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_HttpParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_HttpParameters.html) (`HeaderParameters` 按鍵除外)
+ [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RedshiftDataParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RedshiftDataParameters.html)
+ [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SageMakerPipelineParameters.html)
+ [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SqsParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_SqsParameters.html)

## 許可
<a name="targets-permissions"></a>

若要對您擁有的資源進行 API 呼叫，EventBridge 需要適當的許可。[使用 EventBridge 主控台](eb-create-rule-wizard.md#eb-create-rule-target)或在 中設定 `RoleARN` 參數來指定 IAM 執行角色[https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutTargets.html](https://docs.aws.amazon.com/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 端點，但如果您尚未設定授權，則該角色為選用角色。如需詳細資訊，請參閱 [Amazon EventBridge 和 AWS Identity and Access Management](eb-iam.md)。

如果另一個帳戶位於同一地區，並已授予您許可，您可以將事件傳送至該帳戶。

如需詳細資訊，請參閱[在 Amazon EventBridge 中的 AWS 帳戶之間傳送和接收事件](eb-cross-account.md)。

如果您的目標，例如 Amazon SQS 佇列，使用 AWS Key Management Service (AWS KMS) 加密，您必須在 KMS 金鑰政策中包含下列區段：

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

## AWS Batch 任務佇列做為目標
<a name="targets-specifics-batch"></a>

某些 的 AWS Batch `submitJob`參數可以透過 [BatchParameters](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_BatchParameters.html) 設定。

其他可以在事件裝載中進行指定。如果事件裝載 (透過或經由 [InputTransformers](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html) 傳遞) 包含以下鍵，則它們將映射至 `submitJob` [請求](https://docs.aws.amazon.com/batch/latest/APIReference/API_SubmitJob.html#API_SubmitJob_RequestSyntax)參數：
+ `ContainerOverrides: containerOverrides`
**注意**  
這僅包括命令、環境、記憶體和 vcpus
+ `DependsOn: dependsOn`
**注意**  
這僅包括 jobId
+ `Parameters: parameters`

## CloudWatch Logs 群組做為目標
<a name="targets-specifics-cwl"></a>

如果您未將 [InputTransformer](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html) 與 CloudWatch 日誌搭配使用，則會使用事件裝載作為日誌訊息，且事件來源則用作時間戳記。如果您確實使用 InputTransformer，則模板必須是：

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

EventBridge 會批次處理傳送至日誌串流的項目；因此，EventBridge 可能會將單一或多個事件傳送至日誌串流，視流量而定。

## CodeBuild 專案作為目標
<a name="targets-specifics-codebuild"></a>

EventBridge 支援標準和批次建置做為目標。

如果您使用[輸入轉換器](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html)來塑造來源事件，使其在交付至 CodeBuild 目標之前符合 [StartBuildRequest](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuild.html#API_StartBuild_RequestSyntax) 結構，則參數將依`codeBuild.StartBuild`預設對應 1 對 1，並傳遞至 。

若要改為將參數傳遞至 `codeBuild.StartBuildBatch`，請轉換來源事件以符合 [StartBuildBatchRequest](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuildBatch.html#API_StartBuildBatch_RequestSyntax) 結構，並將下列金鑰/值對新增至轉換事件的根目錄：

`"buildType": "BATCH"`

## Amazon ECS 任務做為目標
<a name="targets-specifics-ecs-task"></a>

如果您使用 [InputTransformers](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html) 將輸入事件塑造為目標，以符合 Amazon ECS RunTask [TaskOverride](https://docs.aws.amazon.com/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.aws.amazon.com/systems-manager/latest/APIReference/API_SendCommand.html](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_SendCommand.html) API。使用 設定目標[https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RunCommandParameters.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_RunCommandParameters.html)，指定要執行的 SSM 文件和目標執行個體或標籤。

`RunCommandParameters` 包含下列欄位：
+ `RunCommandTargets` — （必要） 指定目標執行個體的鍵值對清單。將 `Key`設定為 `InstanceIds` 搭配執行個體 IDs 清單，或將 `Key`設定為 `tag:{{tag-name}}` 搭配標籤值，依標籤將執行個體設為目標。您可以指定 1 到 5 個執行命令目標。

若要指定要執行哪些 SSM 文件並將其傳遞參數，請使用 [https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_Target.html](https://docs.aws.amazon.com/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 文件中定義的參數。

例如，以下 AWS 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 Run Command。這與 不同[https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html](https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_InputTransformer.html)，它會轉換事件承載。使用 Systems Manager Run Command 做為目標時，請在 中設定文件參數，`Input`並在 中指定目標執行個體`RunCommandParameters`。

## Amazon SQS 佇列做為目標
<a name="targets-specifics-sqs"></a>

EventBridge 不支援使用使用 加密的 Amazon SQS 佇列 AWS 擁有的金鑰。這包括目標，以及指定為目標無效字母佇列的 Amazon SQS 佇列。如需詳細資訊 AWS 擁有的金鑰，請參閱《 *AWS Key Management Service 開發人員指南*》中的[AWS 擁有的金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-owned-cmk)。