Pregunta

Después de revisar los documentos, escribí la siguiente plantilla de formación en la nube para crear un tema de SNS, un tema de SQS y suscribir el tema a la cola de 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 formación de la nube se creó correctamente, pero cada vez que publico un mensaje en el tema de SNS, solo recibo el correo electrónico y el mensaje nunca llega a la cola de SQS.

¿Me estoy perdiendo algo en la póliza aquí?¿Existe alguna otra forma de utilizar formaciones de nubes para vincular SNS y SQS?

¿Fue útil?

Solución

Algunas cosas que podrían ayudar:

  • Tengo "Resource": "*" en mi política de cola.
  • Tengo ArnEquals en lugar de StringEquals en el Condition (pero supongo que no importa).
  • Debería poder escapar de la alejamiento de permitir solo "Action": ["sqs:SendMessage"].

Otros consejos

"Resource": {
   "Ref": "CustomResourcesTopic"
 },

Es incorrecto, porque aquí debes usar el Queue Arn

"Resource": {
          "Fn::GetAtt": [
            "CustomResourcesQueue",
            "Arn"
          ]
        },

Y este código también creo que está mal.

"Condition": {
     "StringEquals": {
          "aws:SourceArn": {
                "Ref": "CustomResourcesTopic"
               }
           }
      }

Porque deberías usar el Topic Arn y usar "Ref": "CustomResourcesTopic" obtendrás el nombre del tema

Así será

"Condition": {
         "StringEquals": {
              "aws:SourceArn": "arn:aws:sns:{REGION}:{ACCOUNT_ID}:{TOPIC_NAME}"
               }
          }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top