Why does Set-SQSQueueAttribute fail with an 'InvalidOperationException: Invalid value for the parameter Policy' error? Why does Set-SQSQueueAttribute fail with an 'InvalidOperationException: Invalid value for the parameter Policy' error? powershell powershell

Why does Set-SQSQueueAttribute fail with an 'InvalidOperationException: Invalid value for the parameter Policy' error?


I just ran the example given by powershell using "Get-Help Set-SQSQueueAttribute -Detailed", and it worked without issue.

Based on the PowerShell example working, and the specific error you received, it would suggest there is something amiss with the specific policy you are passing. I would dumb your policy down until it works, and then keep adding things incrementally until it breaks to find out what it doesnt like.

Furthermore:The Set-SQSQueueAttribute method only accepts a MAX of 7 action parameters, AND it does not accept ANY of the ones you mentioned in your code. Valid actions would be:

  • SendMessage
  • ReceiveMessage
  • DeleteMessage
  • ChangeMessageVisibility
  • GetQueueAttributes
  • GetQueueUrl

One thing I noticed different about your example that stood out versus the example that worked for me below is this:

Working example code:

    "Condition": {        "ArnEquals": {          "aws:SourceArn": "$topicarn"          }      }

Your code:

       "Condition": {            "StringEquals": {                 "AWS:SourceOwner": $topicARN            }       }

Example that worked for me:

$qurl = New-SQSQueue -QueueName "myQueue" -Region 'us-east-1' -AccessKey 'accesskey' -SecretKey 'secretkey'$topicarn = New-SNSTopic -Name "myTopic"$qarn = (Get-SQSQueueAttribute -QueueUrl $qurl -AttributeName "QueueArn").QueueARN# construct the policy and inject arns$policy = @"{  "Version": "2008-10-17",  "Id": "$qarn/SQSPOLICY",  "Statement": [      {      "Sid": "1",      "Effect": "Allow",      "Principal": "*",      "Action": "SQS:SendMessage",      "Resource": "$qarn",      "Condition": {        "ArnEquals": {          "aws:SourceArn": "$topicarn"          }      }    }  ]}"@Set-SQSQueueAttribute -QueueUrl $qurl -Attribute @{ Policy=$policy }