[英]How to send SMS through SNS and Cloudwatch?
I am trying to send SMS to my Mobile when my EC2 instance stops. 我尝试在EC2实例停止时将SMS发送到我的手机。
a. 一种。 I selected "Default message type" as "Transactional". 我选择“默认消息类型”作为“事务”。
b. 湾 I created a new IAM role. 我创建了一个新的IAM角色。
IAM role policy IAM角色政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutMetricFilter",
"logs:PutRetentionPolicy"
],
"Resource": [
"*"
]
}
]
}
SNS topic access policy 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:*"
}
}
}
]
}
When the alarm is triggered, I am getting the below error: 触发警报时,出现以下错误:
{
"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"
}
I am unable to understand what permission is it expecting. 我无法理解它需要什么许可。
The cause of the error is most likely due to the policy having incorrect values. 该错误的原因很可能是由于该策略的值不正确。 I'm not sure which values you changed to protect sensitive values, but you'd need to update sns-topic-name
and account-id
. 我不确定您更改了哪些值来保护敏感值,但是您需要更新sns-topic-name
和account-id
。
However, I would recommend another way of achieving your goals... 但是,我建议您实现目标的另一种方式...
You can use Amazon CloudWatch Events to look out for a specific event (eg an instance changing state to Stopped) and have it send a message to Amazon SNS directly (without using an Alarm). 您可以使用Amazon CloudWatch Events查找特定事件(例如,实例将状态更改为“已停止”),并使其直接向Amazon SNS发送消息(不使用警报)。
The steps are: 这些步骤是:
This will then send a message whenever the instance stops. 然后,实例停止时,它将发送一条消息。
It seems the error is due to missing permissions on your IAM role for publishing messages to an SNS topic. 似乎该错误是由于您的IAM角色缺少将消息发布到SNS主题的权限所致。 Make arrangements to attach necessary permissions to the role you use or to the user, like this: 安排将必要的权限附加到您使用的角色或用户身上,如下所示:
{
"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",
]
}
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.