Skip to content

Instantly share code, notes, and snippets.

@slabad
Last active February 3, 2024 20:45
Show Gist options
  • Save slabad/2609d983709feefb2e39023d1fa25c12 to your computer and use it in GitHub Desktop.
Save slabad/2609d983709feefb2e39023d1fa25c12 to your computer and use it in GitHub Desktop.
get_rds_tags
from itertools import chain
import boto3
rds = boto3.client('rds')
tagging = boto3.client('resourcegroupstaggingapi')
# Build a mapping of instance ARNs to details
paginator = rds.get_paginator('describe_db_instances')
instances = {
instance['DBInstanceArn']: instance
for page in paginator.paginate()
for instance in page['DBInstances']
}
# Fetch tag data for all tagged (or previously tagged) RDS DB instances
paginator = tagging.get_paginator('get_resources')
tag_mappings = chain.from_iterable(
page['ResourceTagMappingList']
for page in paginator.paginate(ResourceTypeFilters=['rds:db'])
)
# Add tag detail to each instance
for tag_mapping in tag_mappings:
# Convert list of Key/Value pairs to dict for convenience
tags = {tags['Key']: tags['Value'] for tags in tag_mapping['Tags']}
instances[tag_mapping['ResourceARN']]['Tags'] = tags
# https://dev.to/ajkerrigan/fetch-a-bunch-of-aws-resource-tags-without-being-throttled-4hhc
#
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment