https://github.com/oguzhan-yilmaz/aws-jmespath-utils
jmespath custom functions to filter and exclude AWS resources by tags
https://github.com/oguzhan-yilmaz/aws-jmespath-utils
aws aws-cli jmespath jq tagging tags
Last synced: 5 months ago
JSON representation
jmespath custom functions to filter and exclude AWS resources by tags
- Host: GitHub
- URL: https://github.com/oguzhan-yilmaz/aws-jmespath-utils
- Owner: oguzhan-yilmaz
- License: apache-2.0
- Created: 2024-06-17T14:45:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-24T17:44:00.000Z (almost 2 years ago)
- Last Synced: 2024-07-24T20:28:38.752Z (almost 2 years ago)
- Topics: aws, aws-cli, jmespath, jq, tagging, tags
- Language: Python
- Homepage: https://pypi.org/project/aws-jmespath-utils/
- Size: 31.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-jmespath-utils
## Installation
```bash
pip3 install aws_jmespath_utils
```
## Examples
Check out the example code:
- [examples/01_filter_tags_basic.py](./examples/01_filter_tags_basic.py)
- [examples/02_filter_tags_exclude.py](./examples/02_filter_tags_exclude.py)
## Usage
**Find resources with 'Name' tag set**
```python
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**
```python
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**
```python
jmespath.search( # it's important that your expression array must be inside `` backticks
'[].filter_tags(`["=123*", "=jmespath*"]`, @)', data_list, options=jmespath_options
)
```
**Exclude Tags**
```python
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**
```bash
# set log level as you wish
export AWS_JMESPATH_UTILS_LOG_LEVEL="DEBUG"
export AWS_JMESPATH_UTILS_LOG_LEVEL="INFO" # default
```
## Complete Usage Example
```python
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
)
)
```