

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

# 使用 的 EventBridge 管道範例 AWS CLI
<a name="cli_pipes_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 EventBridge 管道來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

**Topics**
+ [動作](#actions)

## 動作
<a name="actions"></a>

### `create-pipe`
<a name="pipes_CreatePipe_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-pipe`。

**AWS CLI**  
**建立管道**  
下列 `create-pipe` 範例會建立名為 `Demo_Pipe` 的管道，並以 SQS 做為來源，並以 CloudWatch Log Group 做為管道的目標。  

```
aws pipes create-pipe \
    --name Demo_Pipe \
    --desired-state RUNNING \
    --role-arn arn:aws:iam::123456789012:role/service-role/Amazon_EventBridge_Pipe_Demo_Pipe_28b3aa4f \
    --source arn:aws:sqs:us-east-1:123456789012:Demo_Queue \
    --target arn:aws:logs:us-east-1:123456789012:log-group:/aws/pipes/Demo_LogGroup
```
輸出：  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "CREATING",
    "CreationTime": "2024-10-08T12:33:59-05:00",
    "LastModifiedTime": "2024-10-08T12:33:59.684839-05:00"
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreatePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/create-pipe.html)。

### `delete-pipe`
<a name="pipes_DeletePipe_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-pipe`。

**AWS CLI**  
**刪除現有的管道**  
下列 `delete-pipe` 範例會刪除指定帳戶中名為 `Demo_Pipe` 的管道。  

```
aws pipes delete-pipe \
    --name Demo_Pipe
```
輸出：  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "STOPPED",
    "CurrentState": "DELETING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T11:57:22-05:00"
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeletePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/delete-pipe.html)。

### `describe-pipe`
<a name="pipes_DescribePipe_cli_topic"></a>

以下程式碼範例顯示如何使用 `describe-pipe`。

**AWS CLI**  
**擷取 Pipe 的相關資訊**  
下列 `describe-pipe` 範例顯示指定帳戶中 Pipe `Demo_Pipe` 的相關資訊。  

```
aws pipes describe-pipe \
    --name Demo_Pipe
```
輸出：  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "RUNNING",
    "StateReason": "User initiated",
    "Source": "arn:aws:sqs:us-east-1:123456789012:Demo_Queue",
    "SourceParameters": {
        "SqsQueueParameters": {
            "BatchSize": 1
        }
    },
    "EnrichmentParameters": {},
    "Target": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/pipes/Demo_LogGroup",
    "TargetParameters": {},
    "RoleArn": "arn:aws:iam::123456789012:role/service-role/Amazon_EventBridge_Pipe_Demo_Pipe_28b3aa4f",
    "Tags": {},
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T10:23:47-05:00",
    "LogConfiguration": {
        "CloudwatchLogsLogDestination": {
            "LogGroupArn": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/vendedlogs/pipes/Demo_Pipe"
        },
        "Level": "ERROR"
    }
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/describe-pipe.html)。

### `list-pipes`
<a name="pipes_ListPipes_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-pipes`。

**AWS CLI**  
**擷取 Pipes 清單**  
下列 `list-pipes` 範例顯示指定帳戶中的所有管道。  

```
aws pipes list-pipes
```
輸出：  

```
{
    "Pipes": [
        {
            "Name": "Demo_Pipe",
            "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
            "DesiredState": "RUNNING",
            "CurrentState": "RUNNING",
            "StateReason": "User initiated",
            "CreationTime": "2024-10-08T09:29:10-05:00",
            "LastModifiedTime": "2024-10-08T10:23:47-05:00",
            "Source": "arn:aws:sqs:us-east-1:123456789012:Demo_Queue",
            "Target": "arn:aws:logs:us-east-1:123456789012:log-group:/aws/pipes/Demo_LogGroup"
        }
    ]
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPipes](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/list-pipes.html)。

### `list-tags-for-resource`
<a name="pipes_ListTagsForResource_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-tags-for-resource`。

**AWS CLI**  
**列出與現有管道相關聯的標籤**  
下列 `list-tags-for-resource` 範例列出與指定帳戶中名為 `Demo_Pipe` 的管道相關聯的所有標籤。  

```
aws pipes list-tags-for-resource \
    --resource-arn arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe
```
輸出：  

```
{
    "tags": {
        "stack": "Production",
        "team": "DevOps"
    }
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/list-tags-for-resource.html)。

### `start-pipe`
<a name="pipes_StartPipe_cli_topic"></a>

以下程式碼範例顯示如何使用 `start-pipe`。

**AWS CLI**  
**啟動現有的管道**  
下列 `start-pipe` 範例會在指定的帳戶中啟動名為 `Demo_Pipe` 的管道。  

```
aws pipes start-pipe \
    --name Demo_Pipe
```
輸出：  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "STARTING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T10:17:24-05:00"
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的[開始或停止 Amazon EventBridge 管道](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-start-stop.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [StartPipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/start-pipe.html)。

### `stop-pipe`
<a name="pipes_StopPipe_cli_topic"></a>

以下程式碼範例顯示如何使用 `stop-pipe`。

**AWS CLI**  
**停止現有的管道**  
下列 `stop-pipe` 範例會在指定的帳戶中停止名為 `Demo_Pipe` 的管道。  

```
aws pipes stop-pipe \
    --name Demo_Pipe
```
輸出：  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "STOPPED",
    "CurrentState": "STOPPING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T09:29:49-05:00"
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的[開始或停止 Amazon EventBridge 管道](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-start-stop.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [StopPipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/stop-pipe.html)。

### `tag-resource`
<a name="pipes_TagResource_cli_topic"></a>

以下程式碼範例顯示如何使用 `tag-resource`。

**AWS CLI**  
**標記現有的管道**  
下列 `tag-resource` 範例會標記名為 `Demo_Pipe` 的管道。如果命令成功，則不會傳回任何輸出。  

```
aws pipes tag-resource \
    --resource-arn arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe \
    --tags stack=Production
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/tag-resource.html)。

### `untag-resource`
<a name="pipes_UntagResource_cli_topic"></a>

以下程式碼範例顯示如何使用 `untag-resource`。

**AWS CLI**  
**從現有管道移除標籤**  
下列 `untag-resource` 範例從名為 `Demo_Pipe` 的管道移除具有索引鍵 `stack` 的標籤。如果命令成功，則不會傳回任何輸出。  

```
aws pipes untag-resource \
    --resource-arn arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe \
    --tags stack
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/untag-resource.html)。

### `update-pipe`
<a name="pipes_UpdatePipe_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-pipe`。

**AWS CLI**  
**更新現有的管道**  
下列 `update-pipe` 範例會透過新增 CloudWatch 日誌組態參數來更新名為 `Demo_Pipe` 的管道，確保更新管道的執行角色，使其具有日誌目的地的正確權限。  

```
aws pipes update-pipe \
    --name Demo_Pipe \
    --desired-state RUNNING \
    --log-configuration CloudwatchLogsLogDestination={LogGroupArn=arn:aws:logs:us-east-1:123456789012:log-group:/aws/vendedlogs/pipes/Demo_Pipe},Level=TRACE \
    --role-arn arn:aws:iam::123456789012:role/service-role/Amazon_EventBridge_Pipe_Demo_Pipe_28b3aa4f
```
輸出：  

```
{
    "Arn": "arn:aws:pipes:us-east-1:123456789012:pipe/Demo_Pipe",
    "Name": "Demo_Pipe",
    "DesiredState": "RUNNING",
    "CurrentState": "UPDATING",
    "CreationTime": "2024-10-08T09:29:10-05:00",
    "LastModifiedTime": "2024-10-08T11:35:48-05:00"
}
```
如需詳細資訊，請參閱《Amazon EventBridge 使用者指南》**中的 [Amazon EventBridge Pipes 概念](https://docs.aws.amazon.com/eventbridge/latest/userguide/pipes-concepts.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdatePipe](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pipes/update-pipe.html)。