pip3 install aws_jmespath_utils
Check out the example code:
Find resources with 'Name' tag set
jmespath.search( # it's important that your expression array must be inside `` backticks
'[] | filter_tags(`["Name=*"]`, @)', data_list, options=jmespath_options
)
Find tag values starting with 123
jmespath.search( # it's important that your expression array must be inside `` backticks
'[].filter_tags(`["=123*"]`, @)', data_list, options=jmespath_options
)
Find Many tag values
jmespath.search( # it's important that your expression array must be inside `` backticks
'[].filter_tags(`["=123*", "=jmespath*"]`, @)', data_list, options=jmespath_options
)
Exclude Tags
jmespath.search( # it's important that your expression array must be inside `` backticks
'[].exclude_tags(`["map-migrated=*"]`, @)', data_list, options=jmespath_options
)
Setting log levels
# set log level as you wish
export AWS_JMESPATH_UTILS_LOG_LEVEL="DEBUG"
export AWS_JMESPATH_UTILS_LOG_LEVEL="INFO" # default
import jmespath
from aws_jmespath_utils import jmespath_options
import json
data_list = [
{"a": "a", "Tags": [{"Key": "Name", "Value": "jmespath-utils"}, ]},
{"b": "b", "Tags": [{"Key": "Nam", "Value": "jmespath-utils-nam"}]},
{"c": "c", "Tags": [{"Key": "map-migrated", "Value": "234"}]}
]
print(
json.dumps(
jmespath.search('[] | filter_tags(`["Name=*"]`, @)', data_list, options=jmespath_options),
indent=2
)
)
print(
json.dumps(
jmespath.search('[] | exclude_tags(`["Nam*="]`, @)', data_list, options=jmespath_options),
indent=2
)
)