'How to search for AWS resources by tag substring?

I'm trying to obtain a list of all AWS resources that have a particular tag whose value contains a particular substring.

Reason: Our resources are all tagged with ServiceName but for some of these more than one service is applicable. In these cases the applicable services are listed in the tag value, e.g. ServiceName: Service1 / Service2 / Service3.

This blog post seemed very promising... but it seems the functionality in it has since been removed from the Tag Editor, at least from the front-end (would be very interested to know if it still exists in the back-end and could be possibly still accessed by "hacking" the URL???)

I also looked at the get-resources CLI command but this doesn't seem to provide wildcard or substring filtering either.

Open to any other ideas...



Solution 1:[1]

Think I've finally got there with the AWS CLI:

aws resourcegroupstaggingapi get-resources --query 'ResourceTagMappingList[?(@.Tags[?Key==``ServiceName``&&contains(Value,``Service1``)])]'

The above is using a JMESPath expression via the --query parameter.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Steve Chambers