'AWS CLI query filtering oddly

Overall, I am trying to find out which of our SNS topics aren't being used. So I thought to get a list of SNS topics that are active and subtract that from the full list. Seems like that is not so easy. Cloudwatch only reports metrics if there has been activity in the last 6 hours. But it is all I can find, so I will cron a job to grab the active topics every couple of hours and keep a unique list. (If someone has a better idea, I am all ears).

To that end I am building a query to give me the active topic names at a given time. First pass looks like this

aws cloudwatch list-metrics --query 'Metrics[*].Dimensions[*].[Name,Value]' --namespace 'AWS/SNS' --metric-name 'NumberOfMessagesPublished'

That gets me something like this

[
  [
    [
        "TopicName",
        "bogus"
    ]
  ]
]

But I only want the topic name really. So, based on the section "Filtering for specific values" in this AWS doc I modified the query to be

--query 'Metrics[*].Dimensions[?Name=='TopicName'].[Value]'

But all I get back is

[
    []
]

I can't see any difference between the example and my use case. But I must be missing something.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source