- Newest
- Most votes
- Most comments
You need to user the ListQueues API. In there you specify the MaxResults. If there are more results than what you asked, you will receive in the response also a NextToken. You should then invoke the API again and specify the value that you received in the NextToken parameter. This is the way to paginate over all the queues (and other AWS resources).
There is no way in the API for negative filters, but I think you can use a tool like JQ to filter the results on the client side (did not try it).
Here is an example using the paging api on the cli. In this example there are 25 queues, we are limiting each page to 15.
$ aws sqs list-queues --max-items 15
{
"QueueUrls": [
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-01",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-02",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-03",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-04",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-05",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-06",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-07",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-08",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-09",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-10",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-11",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-12",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-13",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-14",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-15"
],
"NextToken": "eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxNX0="
}
That is the first 15 queus, when there are more left it will provide a NextToken
that you need to include in the next request, like:
$ aws sqs list-queues --max-items 15 --starting-token eyJOZXh0VG9rZW4iOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAxNX0=
{
"QueueUrls": [
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-16",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-17",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-18",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-19",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-20",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-21",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-22",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-23",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-24",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-25"
]
}
In the second request, we asked for 15 but there were only 10 left so we don't get a NextToken
and that tells us we are done.
Thanks Dave, ya that's what I've been trying, but the problem is, if the total is more than 1000, then it will stop at #1000, and doesn't return any more even with max-items and NextToken paging...
Ah, this one was tricky. I had to create 1005 queues to figure it out. The 1000 limit appears to be related to the max number of results that will fit in a request made by the client(aws cli itself). When working with more than 1000 queues it looks like you need to adjust both --max-items
and --page-size
to get through. The --page-size
will allow the client to make more requests behind the scenes. Here is how I got through it, your results may vary.
$ aws sqs list-queues --max-items 1000 --page-size 1000 { "QueueUrls": [ "https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-0001", "https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-0002", "https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-0003", ... "https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-0998", "https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-0999", "https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-1000" ], "NextToken": "...TQT09In0=" }
I had to use the --max-items
to get the NextToken to show up...
Then to get the additional queues:
$aws sqs list-queues --max-items 1000 --page-size 1000 --starting-token "...TQT09In0="
{
"QueueUrls": [
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-1001",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-1002",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-1003",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-1004",
"https://sqs.us-west-2.amazonaws.com/123456789123/dk-test-q-1005"
]
}
wow, super! it works! Thank you so much Dave!
Relevant content
- Accepted Answerasked 6 months ago
- asked 4 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago
Thank you Uri for the reply! From the doc, it seems ListQueues is also bounded by 1000 as the maxium, https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ListQueues.html but let me try it out anyways. Thanks!