面向 SQS 队列的云监视事件无法正常工作



根据本文,可以将SQS设置为计划云观看事件的目标:

https://aws.amazon.com/ru/about-aws/whats-new/2016/03/cloudwatch-events-now-supports-amazon-sqs-queue-targets/

我创建了一个简单的云形成模板,旨在每分钟触发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是必填字段:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html

尽管AWS::SQS::Queue根本没有这样的属性(只有 Name 存在(:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-queues.html#aws-properties-sqs-queues-prop

将 SQS 用作目标时,应将哪些内容放入CloudWatch 事件规则目标ID 属性?

提前非常感谢。

我的模板中缺少的部分是AWS::SQS::QueuePolicy

工作模板:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "stack 1",
"Parameters": {},
"Resources": {
"MyPolicy": {
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyDocument": {
"Statement": [{
"Action": "sqs:*",
"Effect": "Allow",
"Resource": {
"Fn::GetAtt": ["MyQueue",
"Arn"]
}
}],
"Version": "2012-10-17"
},
"PolicyName": "MyPolicyName",
"Roles": [{
"Ref": "MyRole"
}]
}
},
"MyRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": ["events.amazonaws.com",
"sqs.amazonaws.com"]
}
}],
"Version": "2012-10-17"
}
}
},
"MyQueue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"QueueName": "MyQueue2"
}
},
"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": "MyRule1",
"Input": "{"a":"b"}"
}]
}
},
"MyQueuePolicy": {
"DependsOn": ["MyQueue", "MyRule"],
"Type": "AWS::SQS::QueuePolicy",
"Properties": {
"PolicyDocument": {
"Version": "2012-10-17",
"Id": "MyQueuePolicy",
"Statement": [{                     
"Effect": "Allow",
"Principal": {
"Service": ["events.amazonaws.com",
"sqs.amazonaws.com"]
},
"Action": "sqs:SendMessage",
"Resource": {
"Fn::GetAtt": ["MyQueue",
"Arn"]
}
}]
},
"Queues": [{
"Ref": "MyQueue"
}]
}
}
},
"Outputs": {        
}
}

最新更新