SNS 및 SQS를 사용하여 클라우드 형성 템플릿을 생성하려고 시도하지만 메시지가 도착하지 않습니다.
-
26-12-2019 - |
문제
문서를 살펴본 후 SQS 주제인 en SNS 주제를 생성하고 해당 주제를 SQS 대기열에 구독하기 위해 다음 클라우드 형성 템플릿을 작성했습니다.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Creates the SNS topic, SQS queue and instance that will service the custom resources queue",
"Parameters": {
"Environment": {
"Description": "Environment in which to manage queues",
"Type": "String",
"Default": "qa",
"AllowedValues": [ "development", "qa", "staging", "production"]
},
"EmailAddress": {
"Description": "Email to where notifications will be sent",
"Type": "String",
"Default": "example@email.com"
}
},
"Resources": {
"CustomResourcesQueue": {
"Type": "AWS::SQS::Queue",
"Properties": {
"ReceiveMessageWaitTimeSeconds": 20,
"VisibilityTimeout": 60,
"QueueName": {
"Fn::Join": ["-", ["cloud_formation_custom_resources", {
"Ref": "Environment"
}]]
}
}
},
"CustomResourcesTopic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"Subscription": [
{
"Endpoint": {
"Ref": "EmailAddress"
},
"Protocol": "email"
},
{
"Endpoint": {
"Fn::GetAtt": ["CustomResourcesQueue", "Arn"]
},
"Protocol": "sqs"
}
]
}
},
"SNSToSQSPolicy": {
"Type": "AWS::SQS::QueuePolicy",
"Properties": {
"PolicyDocument": {
"Id": "PushMessageToSQSPolicy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "allow-sns-to-send-message-to-sqs",
"Effect": "Allow",
"Action": [ "sqs:*" ],
"Principal": {
"AWS": "*"
},
"Resource": {
"Ref": "CustomResourcesTopic"
},
"Condition": {
"StringEquals": {
"aws:SourceArn": {
"Ref": "CustomResourcesTopic"
}
}
}
}
]
},
"Queues": [
{
"Ref": "CustomResourcesQueue"
}
]
}
}
}
}
클라우드 형성이 성공적으로 생성되었지만 SNS 주제에 메시지를 게시할 때마다 이메일만 받고 메시지는 SQS 대기열에 도착하지 않습니다.
여기 정책에서 뭔가 빠졌나요?클라우드 구성을 사용하여 SNS와 SQS를 연결하는 다른 방법이 있습니까?
해결책
도움이 될 수 있는 몇 가지 사항:
- 나는 가지고있다
"Resource": "*"
내 대기열 정책에 있습니다. - 나는 가지고있다
ArnEquals
대신에StringEquals
에Condition
(그러나 그것은 중요하지 않다고 생각합니다). - 당신은 단지 허용함으로써 벗어날 수 있어야합니다
"Action": ["sqs:SendMessage"]
.
다른 팁
"Resource": {
"Ref": "CustomResourcesTopic"
},
.
여기서 큐 ARN
을 사용해야하기 때문에 올바르지 않습니다."Resource": {
"Fn::GetAtt": [
"CustomResourcesQueue",
"Arn"
]
},
.
및이 코드도 틀린 것 같습니다
"Condition": {
"StringEquals": {
"aws:SourceArn": {
"Ref": "CustomResourcesTopic"
}
}
}
.
DE 주제 ARN을 사용하고 "Ref": "CustomResourcesTopic"
를 사용해야하기 때문에 DE TopicName
그래서
"Condition": {
"StringEquals": {
"aws:SourceArn": "arn:aws:sns:{REGION}:{ACCOUNT_ID}:{TOPIC_NAME}"
}
}
. 제휴하지 않습니다 StackOverflow