Skip to main content

jmespath custom functions for filtering AWS resources by tag

Project description

aws-jmespath-utils

Installation

pip3 install aws_jmespath_utils

Examples

Check out the example code:

Usage

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   

Complete Usage Example

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
    )
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_jmespath_utils-0.2.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

aws_jmespath_utils-0.2.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file aws_jmespath_utils-0.2.2.tar.gz.

File metadata

  • Download URL: aws_jmespath_utils-0.2.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.12 Darwin/23.5.0

File hashes

Hashes for aws_jmespath_utils-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f0607b8198c7bdec3f469154f5e0117f258097eb2c6ac736a093a88249f609dc
MD5 a671355d71ddd1f2e4dbbf1e94fada15
BLAKE2b-256 f2a2e61a83e8893fc3a0e2c346fb53d0af79dee92447bb77e409c9441d04964c

See more details on using hashes here.

File details

Details for the file aws_jmespath_utils-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_jmespath_utils-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a96e9d80ab59415bf1f7bac82983be2ec7412cd2b0779555884c20770b05244
MD5 d013be3a90de8fbfbcc77e84da12eb0e
BLAKE2b-256 9f1d0bad2fe634d4b24e23141bd72d81cff4189174dec699e8b268da4a14fda6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page