2

How can I add the below listed SQS permission using AWS CLI command?

    "Statement": [
    {
      "Sid": "Sid8390000202",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "SQS:*",
      "Resource": "arn:aws:sqs:us-east-1:12345678:example-queue",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:us-east-1:73628827939:MySNS"
        }
      }
    }
  ]
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315

2 Answers2

4

You can save the file locally as set-queue-attributes.json with the following policy.

{
  "Id": "Policy1564523767951",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1564523766749",
      "Action": "sqs:*",
      "Effect": "Allow",
      "Resource": "arn:aws:sqs:us-east-1:12345678:example-queue",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:sns:us-east-1:73628827939:MySNS"
        }
      },
      "Principal": "*"
    }
  ]
}

Then execute the following CLI command.

aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/12345678/example-queue --attributes file://set-queue-attributes.json
Michael Quale
  • 568
  • 3
  • 16
4

I had to make a slight addition to the json that @Michael Quale posted to get it working.

{"Policy" : "{\"Id\": \"Policy1564523767951\",\"Version\": \"2012-10-17\",\"Statement\": [{\"Sid\": \"Stmt1564523766749\",\"Action\": \"sqs:*\",\"Effect\": \"Allow\",\"Resource\": \"arn:aws:sqs:us-east-1:12345678:example-queue\",\"Condition\": {\"ArnEquals\": {\"aws:SourceArn\": \"arn:aws:sns:us-east-1:73628827939:MySNS\"}},\"Principal\": \"*\"}]}"}
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • Correct since the attribute you're setting is, in fact, the queue's `Policy` (https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sqs/set-queue-attributes.html) – Marco A. Nov 27 '20 at 16:04