Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation SQS Queue Redrive policy dependency on a DLQ created

I'm using a CloudFormation template to create a stack for SQS. I have one SQS queue set with a dependency to another SQS queue used as a DLQ. When I create the stack I get this error:

Value {"deadLetterTargetArn":"arn:aws:sqs:eu-west-1:xxxxxxxxx:services-abc-dlq","maxReceiveCount":"10"} for parameter RedrivePolicy is invalid. Reason: Dead letter target does not exist.

How do I set a redrive policy to wait for DLQ to finish being created?

Here's the pertinent information from my template:

"Resources": {
    "queueservicesdlqevents": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "DelaySeconds": "0",
        "MaximumMessageSize": "262144",
        "MessageRetentionPeriod": "345600",
        "QueueName": "services-abc-dlq",
        "ReceiveMessageWaitTimeSeconds": "0",
        "VisibilityTimeout": "30"
      }
    },
    "queueservicesevents": {
      "Type": "AWS::SQS::Queue",
      "Properties": {
        "DelaySeconds": "0",
        "MaximumMessageSize": "262144",
        "MessageRetentionPeriod": "345600",
        "QueueName": "services-abc-events",
        "ReceiveMessageWaitTimeSeconds": "20",
        "VisibilityTimeout": "30",
        "RedrivePolicy": {
          "deadLetterTargetArn" : "arn:aws:sqs:eu-west-1:xxxxxx:services-abc-dlq",
          "maxReceiveCount" : 10
        }
      }
    },

Just to add, making a "Ref" to other queue doesn't work because dlqtargetArn expects a string.

like image 795
occasl Avatar asked Sep 10 '15 23:09

occasl


1 Answers

Just to add, making a "Ref" to other queue doesn't work because dlqtargetArn expects a string.

Ref only provides the (default) value of an AWS CloudFormation resource, but you can get the value of other attributes of a resource by means of Fn::GetAtt as follows:

"Fn::GetAtt" : [ "logicalNameOfResource", "attributeName" ]

That is, as per section Return Values within AWS::SQS::Queue, the ARN of the dead letter queue at hand is available via:

"Fn::GetAtt" : [ "queueservicesdlqevents", "Arn" ]

Once you reference the actual ARN from the dependent resource, CloudFormation will ensure that the dependency is created first so that the dead letter target queueservicesdlqevents already exists when you create the queueservicesevents queue.

like image 66
Steffen Opel Avatar answered Sep 24 '22 16:09

Steffen Opel