简体   繁体   中英

How to enumerate all SQS queues in an AWS account

How do I list all SQS queues in an AWS account programmatically via the API and .Net SDK?

I am already doing something similar with DynamoDb tables, and that's fairly straightforward - you can page through results using ListTables in a loop until you have them all.

However the equivalent SQS Api endpoint, ListQueues is different and not as useful. It returns up to 1000 queues, with no option of paging.

Yes, there can be over 1000 queues in my case. I have had a query return exactly 1000 results. It's all in 1 region, so it's not the same as this question .

You can retrieve SQS queue names from Cloudwatch, which supports paging. It will only return queues that are considered active.

An active queue is described as :

A queue is considered active by CloudWatch for up to six hours from the last activity (for example, any API call) on the queue.

Something like this should work:

var client = new AmazonCloudWatchClient(RegionEndpoint.EUWest1);
string nextToken = null;
var results = Enumerable.Empty<string>();

do
{
    var result = client.ListMetrics(new ListMetricsRequest()
    {
        MetricName = "ApproximateAgeOfOldestMessage",
        NextToken = nextToken
    });

    results = results.Concat(
        result
        .Metrics
        .SelectMany(x => x.Dimensions.Where(d => d.Name == "QueueName")
        .Select(d => d.Value))
    );

    nextToken = result.NextToken;

} while (nextToken != null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM