List resources across all regions using the AWS CLI
source link: https://pawelgrzybek.com/list-resources-in-all-regions-using-the-aws-cli/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
List resources across all regions using the AWS CLI
Published: 2023.09.10 · 1 minute read
Today, I needed to list all AWS CloudFormation stacks across all locations under my account. It wasn’t as straightforward as I initially thought because the AWS 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 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 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 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 tablesaws lambda list-functions
- to list Lambda functionsaws rds describe-db-instances
- to list RDS 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!
Leave a comment#
👆 you can use Markdown here
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK