-
-
Save mihow/1070c3ebd6e614a679dc07d420e442aa to your computer and use it in GitHub Desktop.
Using Boto, list all resources in an AWS account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # https://peps.python.org/pep-0723/ | |
| # dependencies = [ | |
| # "boto3" | |
| # ] | |
| # /// | |
| import boto3 | |
| from botocore.exceptions import ClientError | |
| # uses the currently configured profile or "default" | |
| session = boto3.Session() | |
| regions = session.get_available_regions("ec2") | |
| for region in regions: | |
| print(region) | |
| try: | |
| client = session.client("resourcegroupstaggingapi", region_name=region) | |
| for resource in client.get_resources().get("ResourceTagMappingList"): | |
| print(" - ",resource["ResourceARN"]) | |
| for t in resource["Tags"]: | |
| k,v = t.values() | |
| print(f" > {k} = {v}") | |
| except ClientError as e: | |
| print(f"Could not connect to region with error: {e}") | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment