List resources across all regions using the AWS CLI

By admin

Today
DATE

, I needed to list all

AWS CloudFormation
ORG

stacks across all locations under my account. It wasn’t as straightforward as I initially thought because the

AWS
ORG

CLI doesn’t have a single command to do that. The –region all global flag would be nice. Luckily, with a little bit of Bash scripting, we can get the job done.

List of all active regions

The

first
ORDINAL

part of the puzzle is to obtain the list of all active regions.

aws account list-regions –region-opt-status-contains ENABLED ENABLED_BY_DEFAULT

List resources in all regions

The

second
ORDINAL

part is to loop the output of the previous command using the command to list resources in a specific region. In my case, I needed to list

CloudFormation
ORG

stacks, which can be done with the following command:

for region in $( aws account list-regions –region-opt-status-contains ENABLED ENABLED_BY_DEFAULT –query "Regions[].{Region: RegionName}" –output text ) do echo "Region: $region " aws cloudformation list-stacks –region = $region done

With just a few adjustments, you can replace aws cloudformation list-stacks with any other command for different types of resources. Allow me to provide you with some examples.

aws dynamodb list-tables – to list DynamoDB tables

– to list DynamoDB tables aws lambda list-functions – to list

Lambda
PRODUCT

functions

– to list

Lambda
PRODUCT

functions aws rds describe-db-instances – to list

RDS
PRODUCT

databases

Quick and easy copy/pasta type of post 🍝

Did you like it? Please share it with your friends or get me a beer coffee. Thanks! Buy me a coffee All done 👌