Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use ChangeMessageVisibilityBatch
with a CLI
The following code examples show how to use ChangeMessageVisibilityBatch
.
- CLI
-
- Amazon CLI
-
To change multiple messages' timeout visibilities as a batch
This example changes the 2 specified messages' timeout visibilities to 10 hours (10 hours * 60 minutes * 60 seconds).
Command:
aws sqs change-message-visibility-batch --queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue
--entries file://change-message-visibility-batch.json
Input file (change-message-visibility-batch.json):
[
{
"Id": "FirstMessage",
"ReceiptHandle": "AQEBhz2q...Jf3kaw==",
"VisibilityTimeout": 36000
},
{
"Id": "SecondMessage",
"ReceiptHandle": "AQEBkTUH...HifSnw==",
"VisibilityTimeout": 36000
}
]
Output:
{
"Successful": [
{
"Id": "SecondMessage"
},
{
"Id": "FirstMessage"
}
]
}
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example changes the visibility timeout for 2 messages with the specified receipt handles in the specified queue. The first message's visibility timeout is changed to 10 hours (10 hours * 60 minutes * 60 seconds = 36000 seconds). The second message's visibility timeout is changed to 5 hours (5 hours * 60 minutes * 60 seconds = 18000 seconds).
$changeVisibilityRequest1 = New-Object Amazon.SQS.Model.ChangeMessageVisibilityBatchRequestEntry
$changeVisibilityRequest1.Id = "Request1"
$changeVisibilityRequest1.ReceiptHandle = "AQEBd329...v6gl8Q=="
$changeVisibilityRequest1.VisibilityTimeout = 36000
$changeVisibilityRequest2 = New-Object Amazon.SQS.Model.ChangeMessageVisibilityBatchRequestEntry
$changeVisibilityRequest2.Id = "Request2"
$changeVisibilityRequest2.ReceiptHandle = "AQEBgGDh...J/Iqww=="
$changeVisibilityRequest2.VisibilityTimeout = 18000
Edit-SQSMessageVisibilityBatch -QueueUrl https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue -Entry $changeVisibilityRequest1, $changeVisibilityRequest2
Output:
Failed Successful
------ ----------
{} {Request2, Request1}
For a complete list of Amazon SDK developer guides and code examples, see
Using Amazon SQS with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.