EventBridge 使用管道的示例 AWS CLI - AWS SDK 代码示例

文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例

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

EventBridge 使用管道的示例 AWS CLI

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

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

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

主题

操作

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考CreatePipe中的。

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考DeletePipe中的。

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考DescribePipe中的。

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考ListPipes中的。

以下代码示例演示了如何使用 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 概念

以下代码示例演示了如何使用 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 管道

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考StartPipe中的。

以下代码示例演示了如何使用 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 管道

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考StopPipe中的。

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考TagResource中的。

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考UntagResource中的。

以下代码示例演示了如何使用 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 概念

  • 有关 API 的详细信息,请参阅AWS CLI 命令参考UpdatePipe中的。