Skip to content

Instantly share code, notes, and snippets.

@rtrouton
Created August 27, 2021 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtrouton/c9c268662757a6f181b7daa672932a7b to your computer and use it in GitHub Desktop.
Save rtrouton/c9c268662757a6f181b7daa672932a7b to your computer and use it in GitHub Desktop.
Sample code to help identify an RDS database by a specified tag key and that tag's value.
#!/bin/bash
TagKey="Tag Key Goes Here"
TagValue="Tag's Value Goes Here"
aws_region=$(/bin/curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed "s/.$//g")
RDSDatabaseARNIdentifier=$(aws --region "$aws_region" resourcegroupstaggingapi get-resources --resource-type-filters rds:db --query "ResourceTagMappingList[?Tags[? Key == '$TagKey' && Value == '$TagValue']].ResourceARN" --output=text)
RDSDatabaseDBIdentifier=$(aws rds --region "$aws_region" describe-db-instances --db-instance-identifier "$RDSDatabaseARNIdentifier" --query "*[].{DBInstanceIdentifier:DBInstanceIdentifier}" --output text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment