Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Are there any examples of using a JSON file to set queue attributes in AWS CLI


Are there any examples of using a JSON file to set queue attributes in AWS CLI


Yes, you can use a JSON file to set the `ReceiveMessageWaitTimeSeconds` attribute for multiple queues in AWS CLI. Here is an example:

1. Create a JSON File:
Create a JSON file named `set-queue-attributes.json` with the following content:

json
   {
     "ReceiveMessageWaitTimeSeconds": 5
   }
   

2. Set Queue Attributes:
Use the `aws sqs set-queue-attributes` command with the JSON file:

bash
   aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue --attributes file://set-queue-attributes.json
   

This command sets the `ReceiveMessageWaitTimeSeconds` attribute to 5 seconds for the specified queue. You can repeat this process for multiple queues by updating the `queue-url` and the JSON file accordingly.

Here is a more detailed example of setting attributes for multiple queues from a JSON file:

bash
# Create a JSON file
$ echo '{"ReceiveMessageWaitTimeSeconds": 5}' > set-queue-attributes.json

# Set attributes for multiple queues
$ aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue1 --attributes file://set-queue-attributes.json
$ aws sqs set-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue2 --attributes file://set-queue-attributes.json

In this example, the `set-queue-attributes.json` file contains the attribute `ReceiveMessageWaitTimeSeconds` set to 5 seconds. This attribute is applied to both `MyQueue1` and `MyQueue2` using the `aws sqs set-queue-attributes` command[1][2][3].

Citations:
[1] https://awscli.amazonaws.com/v2/documentation/api/2.0.34/reference/sqs/set-queue-attributes.html
[2] https://plainenglish.io/blog/aws-sqs-cli-commands-with-examples-abb9a0f0e362
[3] https://docs.aws.amazon.com/cli/v1/userguide/cli_sqs_code_examples.html
[4] https://docs.aws.amazon.com/cli/latest/reference/sqs/get-queue-attributes.html
[5] https://docs.aws.amazon.com/cli/latest/reference/sqs/set-queue-attributes.html