Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I set ReceiveMessageWaitTimeSeconds for multiple queues at once


Can I set ReceiveMessageWaitTimeSeconds for multiple queues at once


Yes, you can set the `ReceiveMessageWaitTimeSeconds` attribute for multiple SQS queues at once using the AWS CLI. Here is an example of how to do it:

bash
aws sqs set-queue-attributes --queue-url "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue1" --attributes "ReceiveMessageWaitTimeSeconds=20"
aws sqs set-queue-attributes --queue-url "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue2" --attributes "ReceiveMessageWaitTimeSeconds=20"
aws sqs set-queue-attributes --queue-url "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue3" --attributes "ReceiveMessageWaitTimeSeconds=20"

In this example, you are setting the `ReceiveMessageWaitTimeSeconds` attribute to 20 seconds for three different SQS queues. Each queue URL is specified separately, and the attribute is set for each queue individually.

Example with Multiple Queues

You can also set the attribute for multiple queues in a single command by using the `--queue-urls` option:

bash
aws sqs set-queue-attributes --queue-urls "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue1,https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue2,https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue3" --attributes "ReceiveMessageWaitTimeSeconds=20"

In this example, you are setting the `ReceiveMessageWaitTimeSeconds` attribute to 20 seconds for three different SQS queues in a single command. The queue URLs are specified as a comma-separated list.

Example with JSON Input

You can also set the attribute for multiple queues using a JSON input file:

json
[
    {
        "QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue1",
        "Attributes": {
            "ReceiveMessageWaitTimeSeconds": "20"
        }
    },
    {
        "QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue2",
        "Attributes": {
            "ReceiveMessageWaitTimeSeconds": "20"
        }
    },
    {
        "QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue3",
        "Attributes": {
            "ReceiveMessageWaitTimeSeconds": "20"
        }
    }
]

Then, you can use the `--cli-input-json` option to specify the JSON file:

bash
aws sqs set-queue-attributes --cli-input-json file://queues.json

In this example, you are setting the `ReceiveMessageWaitTimeSeconds` attribute to 20 seconds for three different SQS queues using a JSON input file. The JSON file contains the queue URLs and the attribute to be set for each queue. The `--cli-input-json` option is used to specify the JSON file as input to the command[1][2].

Citations:
[1] https://docs.aws.amazon.com/cli/latest/reference/sqs/set-queue-attributes.html
[2] https://tutorialsdojo.com/amazon-sqs/
[3] https://laravel-news.com/amazon-sqs-tips
[4] https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html
[5] https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueAttributes.html