我正在尝试使用支持 SNS 的通知规则为代码管道设置通知。
如图所示,状态为“无法访问”
如果我查看此处的链接aws 故障排除
我已经遵循了所有步骤,甚至在 SNS 主题的访问策略中添加 codestar-notifications 的步骤。
{
"Sid": "AWSCodeStarNotifications_publish",
"Effect": "Allow",
"Principal": {
"Service": "codestar-notifications.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:codestar-notifications:us-east-1:272075499248:notificationrule/50d629524d433dceeafdb6c5fe136e404f29e9e5"
}
但是,状态仍然保持不变,也尝试手动启动管道,但仍然不起作用。
我错过了什么吗?谁能帮我解决这个问题吗?
编辑:
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
"SNS:AddPermission",
"SNS:RemovePermission",
"SNS:DeleteTopic",
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Publish",
"SNS:Receive"
],
"Resource": "arn:aws:sns:us-east-1:272075499248:develop",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "272075499248"
}
}
},
{
"Sid": "AWSCodeStarNotifications_publish",
"Effect": "Allow",
"Principal": {
"Service": "codestar-notifications.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:272075499248:develop"
}
]
}
每当您单独创建SNS主题时,默认访问策略将如下所示:
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:Publish",
"SNS:RemovePermission",
"SNS:SetTopicAttributes",
"SNS:DeleteTopic",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:AddPermission",
"SNS:Subscribe"
],
"Resource": "arn:aws:sns:us-east-2:123456789012:my-sns-topic",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "123456789012"
}
}
}
]
}
以上是错误的,不会让您的 CodePipeline 访问 SNS 主题(使其可访问/“活动”)!将您的 SNS 主题的访问策略更改为以下内容:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "CodeNotification_publish",
"Effect": "Allow",
"Principal": {
"Service": "codestar-notifications.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-2:123456789012:my-sns-topic"
}
]
}
注意 1:将
123456789012
更改为您的 AWS 账户 ID,将 my-sns-topic
更改为您的 SNS 主题的名称。us-east-2
不同,请在上面的代码片段中进行更改。每当您创建通知规则然后创建通知规则目标时,
AWS 刷新通知目标状态的唯一方法是您从CodePipeline -> Settings (on the left side bar) -> Notification rules -> Notification rule targets
中删除
通知规则目标(这非常重要!)。
注意:从通知规则本身删除通知规则目标不会执行任何操作;因此,当您在该页面中重新添加它时,通知规则目标仍将是旧的,因此通知目标状态将保持“无法访问”。
如果完成所有操作后仍然显示无法访问,请再次重复步骤 #1 和 #2,您可能错过了某些内容。
解决此问题的一种方法是使用 CodePipeline 用户界面来创建主题。 这将为您设置所有必需的权限。 创建通知规则时,在“目标”下,选择“创建目标”并输入您要创建的主题的名称。 将使用已设置的权限创建主题。 您只需订阅该主题即可接收通知。
JSON 文件是正确的,但您应该删除并重新创建目标规则
您的管道的 IAM 执行角色可能没有向主题发布消息所需的权限。确保您的管道可以在 IAM 角色和 SNS 策略中发布消息,然后再试一次。一个明显的迹象是 CodePipeline 通知控制台在 SNS 主题旁边显示“无法访问”。
SNS 访问策略如下所示:
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "StatusNotificationsPolicy",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789123:root",
"Service": "codestar-notifications.amazonaws.com"
},
"Action": "sns:Publish",
"Resource": "arn:aws:sns:ap-southeast-2:123456789123:gimme-alerts"
},
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
"SNS:AddPermission",
"SNS:RemovePermission",
"SNS:DeleteTopic",
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Publish",
"SNS:Receive"
],
"Resource": "arn:aws:sns:ap-southeast-2:123456789123:gimme-alerts",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "123456789123"
}
}
}
]
}
以下内容对我有用。
我遵循了 Phil Gilligan 在另一个答案中的建议。当从 CodeCommit 本身创建时,它会自动在 sns 主题中创建访问策略。
根据自己的情况更改账户id和repo名称。
没有其他规则,只有这一规则。似乎规则已经过评估,并且一条规则覆盖了另一条规则。我认为如果一条规则更具限制性,则它优先于另一条规则。
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "CodeNotification_publish",
"Effect": "Allow",
"Principal": {
"Service": "codestar-notifications.amazonaws.com"
},
"Action": "SNS:Publish",
"Resource": "arn:aws:sns:us-east-1:ACCOUNT_ID:REPO_NAME"
}
]
}
关于访问策略的答案是正确的。但更改不会立即应用。很烦人。
只需从 CodePipeline 设置创建新主题。访问策略将自动调整。
对我有用的只是在默认值中添加一个额外的语句对象:
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:GetTopicAttributes",
"SNS:SetTopicAttributes",
"SNS:AddPermission",
"SNS:RemovePermission",
"SNS:DeleteTopic",
"SNS:Subscribe",
"SNS:ListSubscriptionsByTopic",
"SNS:Publish",
"SNS:Receive"
],
"Resource": "arn:aws:sns:us-east-1:XXXXXXXXX:my-awesome-topic",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "XXXXXXXXX"
}
}
},
// added here below
{
"Sid": "1",
"Effect": "Allow",
"Principal": {
"Service": "codestar-notifications.amazonaws.com"
},
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-east-1:XXXXXXXXX:my-awesome-topic"
}
]
}