Interview Prep/Python for DevOps/boto3 & AWS automation

How would you speed up a boto3 script that audits 30 accounts and 17 regions?

AdvancedConceptboto3 & AWS automation
Answer
  • Parallelize across account/region pairs with ThreadPoolExecutor; boto3 calls are I/O bound.
  • Create one Session per thread (Sessions are not thread-safe; clients are), and one client per service and region, reused across calls.
  • Raise max_pool_connections in Config to match workers.
  • Use adaptive retry mode so throttling slows you down instead of failing.
  • Filter server-side (Filters=) rather than downloading everything.
  • Use batch APIs (get_metric_data, Resource Groups Tagging API), or AWS Config advanced queries / Resource Explorer for inventory instead of describe calls at all.
All Python for DevOps questions Roadmap: Python for automation

More on boto3 & AWS automation