根据本文,可以将 SQS 设置为预定的 CloudWatch 事件的目标:
我已经创建了一个简单的云形成模板,该模板旨在每分钟触发一次 CloudWatch 事件,因此新消息应显示在 SQS 中,但是缺少某些内容,因为 SQS 中没有消息。
代码:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "stack 1",
"Parameters": {
},
"Resources": {
"MyQueue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"QueueName": "MyQueue"
}
},
"MyRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"RoleName": "MyRole",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": ["events.amazonaws.com", "lambda.amazonaws.com"]
},
"Action": "sts:AssumeRole"
}]
},
"Path": "/",
"Policies": [{
"PolicyName": "CloudWatchPolicy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "*",
"Resource": "*"
}]
}
}]
}
},
"MyRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "A rule to schedule data update",
"Name": "MyRule",
"ScheduleExpression": "rate(1 minute)",
"State": "ENABLED",
"RoleArn": {
"Fn::GetAtt": ["MyRole",
"Arn"]
},
"Targets": [{
"Arn": {
"Fn::GetAtt": ["MyQueue",
"Arn"]
},
"Id": "MyRule"
}]
}
}
},
"Outputs": {
}
}
那里有什么问题?我应该添加队列侦听器以使消息出现吗?
问题2:
有关 CloudWatch事件规则目标的文档声明 Id 是必填字段:
尽管 AWS :: SQS :: Queue 根本没有这样的属性(仅存在Name):
当将SQS用作目标时,应如何在 CloudWatch Event Rule Target ID属性中添加什么?
非常感谢。
答案 0 :(得分:0)
模板中缺少的部分是 AWS :: SQS :: QueuePolicy 。
工作模板:
3.0
4.0