← All posts

Listing everything in an AWS account with Python

4 May 2023 · 1 min read
#python#boto3#aws

The console is fine for looking at one thing. When I want to know everything in an account, I write a few lines of Python.

The pattern I reuse:

  • One session per account and region. boto3 makes it easy to loop through regions, because resources hide in the ones you forgot about.
  • Always use paginators. API calls return results in pages. Without a paginator you quietly get only the first 50 and think you've seen everything.
  • Write to CSV. A spreadsheet is still the fastest way to sort, filter and share what you found.
  • Read-only role. Inventory scripts only need to read. Give them nothing else.

The first time I ran one across all regions, I found a test instance someone had launched in a region nobody used. It had been running for months.

T
Written by Teza Wynn Htut

Cloud and infrastructure engineer in Auckland. I write down the fixes and lessons from things I build, and make tutorial videos on YouTube.

Watch on YouTube