Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active August 3, 2022 09:56
Show Gist options
  • Save xbalaji/2722b4ee9a7a88bfd0fdd5feeb8cf22a to your computer and use it in GitHub Desktop.
Save xbalaji/2722b4ee9a7a88bfd0fdd5feeb8cf22a to your computer and use it in GitHub Desktop.
aws list resources
# list all regions
aws ec2 describe-regions --output text | cut -f3-
# the use resourcegrouptaggingapi to list resources in each region
aws resourcegroupstaggingapi get-resources --region ${REG_NAME} | jq -r '.[][] | .ResourceARN'
aws resourcegroupstaggingapi get-resources --tag-filters "Key=XYZ" | jq -r '.[][] | .ResourceARN as $res | .Tags[] | select(.Key == "XYZ") | [$res, .Value ] | @csv '
# display all non-us regions
aws ec2 describe-regions | jq -r '.Regions[] | select(.RegionName | test("^(?!(us-).*)")) | .RegionName'
# display all resources in non-us regions
aws ec2 describe-regions | jq -r '.Regions[] | select(.RegionName | test("^(?!(us-).*)")) | .RegionName' | xargs -t -L 1 -I {} aws resourcegroupstaggingapi get-resources --region {} | jq -r '.ResourceTagMappingList[].ResourceARN'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment