Skip to content

Instantly share code, notes, and snippets.

@aheld
Created June 30, 2016 18:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aheld/a421b7a9d2f310960910d2ea991b726e to your computer and use it in GitHub Desktop.
Save aheld/a421b7a9d2f310960910d2ea991b726e to your computer and use it in GitHub Desktop.
get RDS tags using AWS cli , this really seems too complicated
#!/bin/bash
REGION="us-east-1"
PROFILE="prod"
get_account_id(){
aws ec2 describe-security-groups \
--group-names 'Default' \
--query 'SecurityGroups[0].OwnerId' \
--output text \
--profile "$PROFILE"
}
ACCOUNT_ID=$(get_account_id)
list_rds() {
aws rds describe-db-instances \
--query "DBInstances[].[DBInstanceIdentifier]" \
--output text \
--profile "$PROFILE"
}
get_rds_tags() {
aws rds list-tags-for-resource --resource-name "$1" \
--query "TagList[]" \
--output text \
--profile "$PROFILE"
# --query "TagList[?Key == 'vnoc-rsg']" \
# --query "TagList[?(Key =='project' ||Key == 'vnoc-rsg')]" \
}
for id in $(list_rds)
do
echo arn:aws:rds:$REGION:$ACCOUNT_ID:db:$id
get_rds_tags arn:aws:rds:$REGION:$ACCOUNT_ID:db:$id
echo ""
done
@amitsaha
Copy link

This is still the only way to do it it seems.

I came up with this one liner and it seemed to work for me:
aws rds describe-db-instances --query "DBInstances[].DBInstanceArn" | grep "arn" | awk -F "," '{print $1}' | xargs -i sh -c 'echo {}; aws rds list-tags-for-resource --resource-name {}'

@joeyciechanowicz
Copy link

From this issue you can now do this with the resourcegroupstaggingapi

aws resourcegroupstaggingapi get-resources --resource-type-filters rds:db --tag-filters Key=Level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment