Listing of all resources in all AWS regions (shell script)
Shuichi
Posted on October 20, 2020
This allows you to see the overall resources without having to check for each region and each service.
When you close your AWS Account, it also helps you to see if there are any active resources left over.
if you have any active resources and terminate them before you close your account
Script
get-resources.sh
for region in `aws ec2 describe-regions --query 'Regions[].RegionName' --region us-west-1 --output text`
do
echo "region = ${region}"
aws resourcegroupstaggingapi get-resources --region ${region} --query 'ResourceTagMappingList[].ResourceARN';
done
- For each region fetched by describe-regions, I use resourcegroupstaggingapi get-resources.
- It's OK to do describe-regions at any region, so I've set it to us-west-1.
Prerequisites
- aws cli is installed.
Usage
Run
export AWS_PROFILE=xxxx # Not necessary if you always set the default profile.
sh get-resources.sh
Output
region = eu-north-1
[]
region = ap-south-1
[]
region = eu-west-3
[]
region = eu-west-2
[]
region = eu-west-1
[]
region = ap-northeast-2
[]
region = ap-northeast-1
[
"arn:aws:apigateway:ap-northeast-1::/restapis/〜/stages/devA",
"arn:aws:apigateway:ap-northeast-1::/restapis/〜/stages/devB",
〜
"arn:aws:ec2:ap-northeast-1:111111111111:vpc/vpc-1111111a",
"arn:aws:ec2:ap-northeast-1:111111111111:vpc/vpc-1111111b",
〜
"arn:aws:lambda:ap-northeast-1:111111111111:function:xxxx-checker",
"arn:aws:lambda:ap-northeast-1:111111111111:function:xxxx-deleter",
〜
...
Notes
If there is a service that is not supported by the resourcegroupstaggingapi, it will not be listed.
Reference
ec2/describe-regions
https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-regions.html
Used for listing regions
resourcegroupstaggingapi/get-resources
https://docs.aws.amazon.com/cli/latest/reference/resourcegroupstaggingapi/get-resources.html
Used for listing resources
How do I close my AWS account?
https://aws.amazon.com/premiumsupport/knowledge-center/close-aws-account/?nc1=h_ls
Posted on October 20, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 28, 2024