当我的EC2实例停止时,我正在尝试向手机发送短信。
a。我选择“默认消息类型”作为“事务”。
b。我创建了一个新的IAM角色。
IAM角色政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutMetricFilter",
"logs:PutRetentionPolicy"
],
"Resource": [
"*"
]
}
]
}
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:Receive",
"SNS:AddPermission",
"SNS:Subscribe"
],
"Resource": "arn:aws:sns:us-west-2:account-id:sns-topic-name",
"Condition": {
"StringEquals": {
"AWS:SourceOwner": "account-id"
},
"ArnLike": {
"AWS:SourceArn": "arn:aws:cloudwatch:us-west-2:account-id:alarm:*"
}
}
}
]
}
触发警报时,出现以下错误:
{
"actionState": "Failed",
"stateUpdateTimestamp": 1561102479560,
"notificationResource": "arn:aws:sns:us-west-2:account-id:sns-topic-name",
"publishedMessage": null,
"error": "Resource: arn:aws:cloudwatch:us-west-2:account-id:alarm:alarm-name is not authorized to perform: SNS:Publish on resource: arn:aws:sns:us-west-2:account-id:sns-topic-name"
}
我无法理解它需要什么许可。
答案 0 :(得分:1)
错误原因很可能是由于该策略的值不正确。我不确定为保护敏感值而更改了哪些值,但是您需要更新sns-topic-name
和account-id
。
但是,我建议您实现目标的另一种方式...
您可以使用 Amazon CloudWatch Events 查找特定事件(例如,实例将状态更改为“已停止”),并使其直接向Amazon SNS发送消息(不使用警报)。 / p>
步骤是:
这将在实例停止时发送一条消息。
答案 1 :(得分:0)
该错误似乎是由于IAM角色缺少将消息发布到SNS主题的权限所致。安排将必要的权限附加到您使用的角色或用户身上,如下所示:
{
"Id": "Policy1415489375392",
"Statement": [
{
"Sid": "AWSConfigSNSPolicy20150201",
"Action": [
"SNS:Publish"
],
"Effect": "Allow",
"Resource": "arn:aws:sns:region:account-id:myTopic",
"Principal": {
"AWS": [
"account-id1",
"account-id2",
"account-id3",
]
}
}
]
}