How do you iterate over all regions?
IntermediateConceptboto3 & AWS automation
Answer
regions = [r["RegionName"] for r in
boto3.client("ec2", region_name="us-east-1").describe_regions(
Filters=[{"Name": "opt-in-status", "Values": ["opt-in-not-required", "opted-in"]}]
)["Regions"]]
describe_regions returns only enabled regions by default (add AllRegions=True to see disabled ones). boto3.Session().get_available_regions("ec2") comes from the SDK's local data and may include regions not enabled for your account, which then fail with AuthFailure or UnrecognizedClientException.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner