

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

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

以下代码示例向您展示了如何使用 with Pip EventBridge es 来执行操作和实现常见场景。 AWS Command Line Interface 

*操作*是大型程序的代码摘录，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

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

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

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

以下代码示例演示了如何使用 `create-pipe`。

**AWS CLI**  
**创建管道**  
以下`create-pipe`示例创建了一个名为 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"
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_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"
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_topic"></a>

以下代码示例演示了如何使用 `describe-pipe`。

**AWS CLI**  
**检索有关管道的信息**  
以下 `describe-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"
    }
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_topic"></a>

以下代码示例演示了如何使用 `list-pipes`。

**AWS CLI**  
**检索管道的列表**  
以下 `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"
        }
    ]
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_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"
    }
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_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"
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的启动或停止亚马逊 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_2_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"
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的启动或停止亚马逊 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_2_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
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_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
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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_2_topic"></a>

以下代码示例演示了如何使用 `update-pipe`。

**AWS CLI**  
**更新现有管道**  
以下`update-pipe`示例`Demo_Pipe`通过添加 CloudWatch 日志配置参数来更新名为的 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"
}
```
有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的 Amaz* on Pip EventBridge es 概念](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)*中的。