SetQueueAttributes

Description

The SetQueueAttributes action sets an attribute of a queue. Currently, you can set two attributes for a queue: VisibilityTimeout and Policy. When you change a queue's attributes, the change can take up to 60 seconds to propagate throughout the SQS system.

[Important]Important

Before the 2007-05-01 release introduced the SetQueueAttributes action, you set the visibility timeout by using the SetVisibilityTimeout action. As of the 2008-01-01 release of Amazon SQS, the SetVisibilityTimeout action is no longer supported.

Request Parameters

The following table lists the special request parameters the SetQueueAttributes action uses in addition to the common request parameters all actions use (for more information, see Request Parameters Common to All Actions).

NameDescriptionRequired

Attribute.Name

The name of the attribute you want to set, either VisibilityTimeout or Policy. For more information about VisibilityTimeout, see Visibility Timeout. For more information about Policy, see Basic Policy Structure.

Type: String

Valid Values: VisibilityTimeout | Policy

Default: None

Yes

Attribute.Value

The value of the attribute you want to set. To delete a queue's access control policy, set the policy to "".

Constraints: For VisibilityTimeout, the value must be an integer from 0 to 43200 (maximum 12 hours). For Policy, the value must be a valid form-url-encoded policy. For more information about policy structure, see Basic Policy Structure. For more information about form-url-encoding, see http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1.

Default: None

Yes

Response Elements

The response contains no special elements besides the common elements in all successful responses (for more information, see Structure of a Successful Response).

Special Errors

The following table lists the special errors the SetQueueAttributes action returns in addition to the common errors all actions return (for more information, see Errors Common to all Actions).

ErrorDescriptionHTTP Status Code

InvalidAttributeName

Unknown attribute

400

Examples

Sample Request with Policy

The following example Query request sets a policy that gives all users ReceiveMessage permission for the queue named 195004372649/testQueue.

https://queue.amazonaws.com?SignatureVersion=1
&Action=SetQueueAttributes
&Version=2009-02-01
&Attribute.1.Name=Policy
&Attribute.1.Value=%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22
%3A%22%2F195004372649%2FtestQueue%2FSQSDefaultPolicy%22%2C%22Stat
ement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22Effe
ct%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D
%2C%22Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%
22%2F195004372649%2FtestQueue%22%7D%5D%7D
&Timestamp=2009-05-06T16%3A57%3A31.000Z
&AWSAccessKeyId=0AZAVD7PQ3DCC3452ZG2
&Signature=%2Bd7ZlPIdnb%2BhpEna2TgfwQjfGF8%3D

The above policy value is form-url-encoded from the following text:

{
    "Version":"2008-10-17",
    "Id":"/195004372649/testQueue/SQSDefaultPolicy",
    "Statement":  [
        {
        "Sid":"Queue1ReceiveMessage",
        "Effect":"Allow",
        "Principal":{"AWS":"*"},
        "Action":"SQS:ReceiveMessage",
        "Resource":"/195004372649/testQueue"
        }
    ]    
}

For more examples of policies, see Amazon SQS Policy Examples.

Sample Request with VisibilityTimeout

The following example Query request sets the visibility timeout to 35 seconds for the queue named 123456789012/testQueue.

http://queue.amazonaws.com/123456789012/testQueue/
?Action=SetQueueAttributes
&Attribute.1.Name=VisibilityTimeout
&Attribute.1.Value=35
&Version=2009-02-01
&SignatureMethod=HmacSHA256
&Expires=2009-04-18T22%3A52%3A43PST
&AWSAccessKeyId=0GS7553JW74RRM612K02EXAMPLE
&SignatureVersion=2
&Signature=Dqlp3Sd6ljTUA9Uf6SGtEExwUQEXAMPLE

Sample Response

<SetQueueAttributesResponse>
    <ResponseMetadata>
        <RequestId>
            e5cca473-4fc0-4198-a451-8abb94d02c75
        </RequestId>
    </ResponseMetadata>
</SetQueueAttributesResponse>

Related Actions