How to list available regions with Boto3 Python
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Listing AWS regions with Boto3 is a common step in deployment and auditing automation. The tricky part is that region availability differs by service, partition, and account policy. A robust approach discovers regions dynamically per service and then filters by organization constraints.
Discover Regions for a Service
Boto3 exposes service specific region discovery through Session.get_available_regions.
This gives known EC2 regions for the session partition context. It does not guarantee every region is enabled for your account.
Compare Region Coverage Across Services
If your automation depends on multiple services, compare their region sets.
This prevents selecting regions where one required service is unavailable.
Handle Profiles and Partitions Explicitly
Different AWS profiles may map to different accounts and permissions. Also, commercial, GovCloud, and China partitions have different region catalogs.
Document partition assumptions in your scripts. Silent partition mismatch can produce confusing region lists.
Verify Region Usability with Credential Probe
A region may exist but still be unusable for your account due to policy restrictions. Add lightweight API probes for critical workflows.
For strict automation, fail early when no usable region is found.
Build a Reusable Discovery Helper
Encapsulate region discovery and filtering in one function so every script follows the same logic.
This pattern keeps policy logic centralized and easier to test.
Integrate Region Discovery into Deployment Workflows
Typical production flow:
- Discover service regions.
- Intersect with policy allowlist.
- Probe account usability if needed.
- Execute per region jobs.
- Record final selected region list in logs.
Persisting final selection helps incident response when policy or AWS availability changes.
Operational Recommendations
- Cache region discovery results for short durations in long running tools.
- Recompute periodically to pick up new AWS regions.
- Avoid hardcoded region lists in repositories unless policy requires strict pinning.
- Keep profile and partition settings explicit in automation configuration.
These practices reduce surprise failures in multi region operations.
Export Region Inventory for Audits
Security and platform teams often need a saved snapshot of discovered regions. You can export service region inventories to JSON for review.
Keeping these snapshots in audit artifacts helps explain changes when AWS adds regions or organizational policy updates take effect.
Common Pitfalls
- Hardcoding one global region list and assuming all services share it.
- Treating available regions as account enabled regions without probing.
- Ignoring partition differences across commercial and specialized environments.
- Forgetting explicit profile selection and using unexpected credentials.
- Skipping logging of final region set used by deployment jobs.
Summary
- Discover regions dynamically per service with Boto3 sessions.
- Compare service footprints when workflows need multiple AWS services.
- Filter by policy allowlists and probe account usability when needed.
- Encapsulate discovery logic in reusable helper functions.
- Log selected regions so operations remain traceable and debuggable.
Related reading
- How to list kubernetes services in k9s?
- How to load a pickle file from S3 to use in AWS Lambda?
- How to load npm modules in AWS Lambda?
- How to log all Cognito User details in API Gateway Cloudwatch
- How to list imported modules?
- How to list Kafka consumer group using python
- How to make 10,000 files in S3 public
- How to make a daily back up of my ec2 instance?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.