8

I am trying to set redrive policy for SQS using the AWS CLI Command below , but seeing an error related to redrive JSON. Can you please let me know how I can fix this?

redrive_policy="{\"RedrivePolicy\":{\"deadLetterTargetArn\":\"$dlq_arn\",\"maxReceiveCount\":\"15\"}}"

AWS CLI COMMAND

aws sqs set-queue-attributes --queue-url https://queue.amazonaws.com/12345678/test-queue --attributes $redrive_policy --region=us-east-1

Error Message

Parameter validation failed: Invalid type for parameter Attributes.RedrivePolicy, value: OrderedDict([(u'deadLetterTargetArn', u'arn:aws:sqs:us-east-1:12345678:dlq'), (u'maxReceiveCount', u'15')]), type: , valid types:

Punter Vicky
  • 14,140
  • 41
  • 164
  • 279

2 Answers2

11

Have you tried just creating the JSON in a separate file and passing it as an argument to your AWS CLI command? I find it's difficult to get all of the escaping correct when passing the JSON as a parameter. So you'd basically do it as the example shows in the AWS documentation:

https://docs.aws.amazon.com/cli/latest/reference/sqs/set-queue-attributes.html#examples

  1. So first you'd create a new file called "set-queue-attributes.json" like so:
    {
      "DelaySeconds": "10",
      "MaximumMessageSize": "131072",
      "MessageRetentionPeriod": "259200",
      "ReceiveMessageWaitTimeSeconds": "20",
      "RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:80398EXAMPLE:MyDeadLetterQueue\",\"maxReceiveCount\":\"1000\"}",
      "VisibilityTimeout": "60"
    }
  1. Then run the command like this:
aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyNewQueue --attributes file://set-queue-attributes.json --region=us-east-1
Brod
  • 1,357
  • 11
  • 14
  • 1
    Thanks , I just figured that I missed the double quotes for redrive policy. It worked fine after I added that – Punter Vicky Jul 30 '19 at 16:06
  • Any tips on how to remove it afterwards? I tried omitting the `RedrivePolicy` field from the JSON but no luck so far... – Ondrej Burkert Dec 21 '20 at 16:48
  • @PunterVicky - I am trying to do the exact thing with the Policy attribute. Getting an identical error. What did you fix? – JDBennett Aug 10 '21 at 15:23
  • @JDBennett it’s been quite a while but I believe I removed the double quotes when assigning the value to redrive_policy variable – Punter Vicky Aug 11 '21 at 16:11
  • I got it figured out. It is the double quotes - need to use single quotes wrapping escaped json. Double quotes remove the escaping and turn it back into proper json. – JDBennett Aug 12 '21 at 12:55
2

if you want to run in the same command you can use this example:

aws sqs set-queue-attributes \
--queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyNewQueue \
--attributes '{
    "RedrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:80398EXAMPLE:MyDeadLetterQueue\",\"maxReceiveCount\":\"1000\"}",
    "MessageRetentionPeriod": "259200",
    "VisibilityTimeout": "90"
}'
Pedro Bacchini
  • 757
  • 8
  • 12