本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
AWS CodeStar 使用通知示例 Amazon CLI
以下代码示例向您展示了如何使用 with Notifications 来执行操作和实现常见场 AWS CodeStar 景。 Amazon Command Line Interface
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。
场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。
每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示如何使用 create-notification-rule
。
- Amazon CLI
-
创建通知规则
以下
create-notification-rule
示例使用名为的 JSON 文件rule.json
为指定 Amazon 账户MyDemoRepo
中名MyNotificationRule
为的存储库创建名为的通知规则。创建分支和标签时,带有FULL
详细信息的通知将发送到指定的目标 Amazon SNS 主题。aws codestar-notifications create-notification-rule \ --cli-input-json file://rule.json
rule.json
的内容:{ "Name": "MyNotificationRule", "EventTypeIds": [ "codecommit-repository-branches-and-tags-created" ], "Resource": "arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo", "Targets": [ { "TargetType": "SNS", "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic" } ], "Status": "ENABLED", "DetailType": "FULL" }
输出:
{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的创建通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考CreateNotificationRule
中的。
-
以下代码示例演示如何使用 delete-notification-rule
。
- Amazon CLI
-
删除通知规则
以下
delete-notification-rule
示例删除了指定的通知规则。aws codestar-notifications delete-notification-rule \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE
输出:
{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的删除通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteNotificationRule
中的。
-
以下代码示例演示如何使用 delete-target
。
- Amazon CLI
-
删除通知规则目标
以下
delete-target
示例将指定目标从所有配置为用作目标的通知规则中移除,然后删除该目标。aws codestar-notifications delete-target \ --target-address arn:aws:sns:us-east-1:123456789012:MyNotificationTopic \ --force-unsubscribe-all
此命令不生成任何输出。
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的删除通知规则目标。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DeleteTarget
中的。
-
以下代码示例演示如何使用 describe-notification-rule
。
- Amazon CLI
-
检索通知规则的详细信息
以下
describe-notification-rule
示例检索指定通知规则的详细信息。aws codestar-notifications describe-notification-rule \ --arn arn:aws:codestar-notifications:us-west-2:123456789012:notificationrule/dc82df7a-EXAMPLE
输出:
{ "LastModifiedTimestamp": 1569199844.857, "EventTypes": [ { "ServiceName": "CodeCommit", "EventTypeName": "Branches and tags: Created", "ResourceType": "Repository", "EventTypeId": "codecommit-repository-branches-and-tags-created" } ], "Status": "ENABLED", "DetailType": "FULL", "Resource": "arn:aws:codecommit:us-west-2:123456789012:MyDemoRepo", "Arn": "arn:aws:codestar-notifications:us-west-w:123456789012:notificationrule/dc82df7a-EXAMPLE", "Targets": [ { "TargetStatus": "ACTIVE", "TargetAddress": "arn:aws:sns:us-west-2:123456789012:MyNotificationTopic", "TargetType": "SNS" } ], "Name": "MyNotificationRule", "CreatedTimestamp": 1569199844.857, "CreatedBy": "arn:aws:iam::123456789012:user/Mary_Major" }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的 “查看通知规则”。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeNotificationRule
中的。
-
以下代码示例演示如何使用 list-event-types
。
- Amazon CLI
-
获取通知规则的事件类型列表
以下
list-event-types
示例检索 CodeDeploy 应用程序的所有可用通知事件类型的筛选列表。相反,如果您不使用任何过滤器,则该命令将返回所有资源类型的所有通知事件类型。aws codestar-notifications list-event-types \ --filters Name=SERVICE_NAME,Value=CodeDeploy
输出:
{ "EventTypes": [ { "EventTypeId": "codedeploy-application-deployment-succeeded", "ServiceName": "CodeDeploy", "EventTypeName": "Deployment: Succeeded", "ResourceType": "Application" }, { "EventTypeId": "codedeploy-application-deployment-failed", "ServiceName": "CodeDeploy", "EventTypeName": "Deployment: Failed", "ResourceType": "Application" }, { "EventTypeId": "codedeploy-application-deployment-started", "ServiceName": "CodeDeploy", "EventTypeName": "Deployment: Started", "ResourceType": "Application" } ] }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的创建通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListEventTypes
中的。
-
以下代码示例演示如何使用 list-notification-rules
。
- Amazon CLI
-
检索通知规则列表
以下
list-notification-rules
示例检索指定 Amazon 区域中所有通知规则的列表。aws codestar-notifications list-notification-rules --region us-east-1
输出:
{ "NotificationRules": [ { "Id": "dc82df7a-EXAMPLE", "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }, { "Id": "8d1f0983-EXAMPLE", "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/8d1f0983-EXAMPLE" } ] }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的 “查看通知规则”。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListNotificationRules
中的。
-
以下代码示例演示如何使用 list-tags-for-resource
。
- Amazon CLI
-
获取附加到通知规则的标签列表
以下
list-tags-for-resource
示例检索附加到指定通知规则的所有标签的列表。在此示例中,通知规则当前没有与之关联的标签。aws codestar-notifications list-tags-for-resource \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE
输出:
{ "Tags": {} }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的创建通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListTagsForResource
中的。
-
以下代码示例演示如何使用 list-targets
。
- Amazon CLI
-
检索通知规则目标列表
以下
list-targets
示例检索指定 Amazon 区域中所有通知规则目标的列表。aws codestar-notifications list-targets \ --region us-east-1
输出:
{ "Targets": [ { "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MySNSTopicForNotificationRules", "TargetType": "SNS", "TargetStatus": "ACTIVE" }, { "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MySNSTopicForNotificationsAboutMyDemoRepo", "TargetType": "SNS", "TargetStatus": "ACTIVE" } ] }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的查看通知规则目标。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考ListTargets
中的。
-
以下代码示例演示如何使用 subscribe
。
- Amazon CLI
-
向通知规则中添加目标
以下
subscribe
示例将 Amazon SNS 主题添加为指定通知规则的目标。aws codestar-notifications subscribe \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE \ --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic
输出:
{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }
有关更多信息,请参阅Amazon 开发者工具控制台用户指南中的添加或删除作为通知规则目标的 Amazon SNS 主题。
-
有关 API 详细信息,请参阅《Amazon CLI Command Reference》中的 Subscribe
。
-
以下代码示例演示如何使用 tag-resource
。
- Amazon CLI
-
向通知规则添加标签
以下
tag-resource
示例将密钥名称为Team
、值Li_Juan
为的标签添加到指定的通知规则。aws codestar-notifications tag-resource \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE \ --tags Team=Li_Juan
输出:
{ "Tags": { "Team": "Li_Juan" } }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的创建通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考TagResource
中的。
-
以下代码示例演示如何使用 unsubscribe
。
- Amazon CLI
-
从通知规则中移除目标
以下
unsubscribe
示例将作为目标的 Amazon SNS 主题从指定的通知规则中删除。aws codestar-notifications unsubscribe \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE \ --target TargetType=SNS,TargetAddress=arn:aws:sns:us-east-1:123456789012:MyNotificationTopic
输出:
{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic" }
有关更多信息,请参阅Amazon 开发者工具控制台用户指南中的添加或删除作为通知规则目标的 Amazon SNS 主题。
-
有关 API 详细信息,请参阅《Amazon CLI Command Reference》中的 Unsubscribe
。
-
以下代码示例演示如何使用 untag-resource
。
- Amazon CLI
-
从通知规则中移除标签
以下
untag-resource
示例Team
从指定的通知规则中删除带有密钥名称的标签。aws codestar-notifications untag-resource \ --arn arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/fe1efd35-EXAMPLE \ --tag-keys Team
此命令不生成任何输出。
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的编辑通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UntagResource
中的。
-
以下代码示例演示如何使用 update-notification-rule
。
- Amazon CLI
-
更新通知规则
以下
update-notification-rule
示例123456789012
使用名为的 JSON 文件更新 Amazon 账户MyNotificationRule
中名为的通知规则update.json
。aws codestar-notifications update-notification-rule \ --cli-input-json file://update.json
update.json
的内容:{ "Name": "MyUpdatedNotificationRule", "EventTypeIds": [ "codecommit-repository-branches-and-tags-created" ], "Resource": "arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo", "Targets": [ { "TargetType": "SNS", "TargetAddress": "arn:aws:sns:us-east-1:123456789012:MyNotificationTopic" } ], "Status": "ENABLED", "DetailType": "FULL" }
输出:
{ "Arn": "arn:aws:codestar-notifications:us-east-1:123456789012:notificationrule/dc82df7a-EXAMPLE" }
有关更多信息,请参阅《Amazon 开发者工具控制台用户指南》中的编辑通知规则。
-
有关 API 的详细信息,请参阅Amazon CLI 命令参考UpdateNotificationRule
中的。
-