Cercando di creare un modello di formazione cloud con SNS e SQS funziona, ma i messaggi non arrivano mai
-
26-12-2019 - |
Domanda
Dopo aver attraversato i Documenti, ho scritto il seguente modello di formazione cloud per creare argomento EN SNS, un argomento SQS e sottoscrivere l'argomento alla coda 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"
}
]
}
}
}
}
.
La formazione cloud è creata con successo, ma ogni volta che pubblico un messaggio all'argomento SNS, ricevo solo l'e-mail, il messaggio non arriva mai alla coda SQS.
Mi manca qualcosa nella politica qui?C'è qualche altro modo per utilizzare le formazioni cloud per legare SNS e SQS?
Soluzione
Alcune cose che potrebbero aiutare:
- .
- Ho
"Resource": "*"
nella mia politica della coda. - Ho
ArnEquals
invece diStringEquals
sulCondition
(ma immagino che non importa). - Dovresti essere in grado di allontanarti con permettendo solo
"Action": ["sqs:SendMessage"]
.
Altri suggerimenti
"Resource": {
"Ref": "CustomResourcesTopic"
},
.
Non è corretto, perché qui devi usare la coda ARN
"Resource": {
"Fn::GetAtt": [
"CustomResourcesQueue",
"Arn"
]
},
.
E questo codice penso anche che sia sbagliato
"Condition": {
"StringEquals": {
"aws:SourceArn": {
"Ref": "CustomResourcesTopic"
}
}
}
.
Perché dovresti usare De Argic ARN e utilizzare "Ref": "CustomResourcesTopic"
che otterrai De TopicName
Allora, sarà
"Condition": {
"StringEquals": {
"aws:SourceArn": "arn:aws:sns:{REGION}:{ACCOUNT_ID}:{TOPIC_NAME}"
}
}
.