How does boto3 decide the region, and what is the gotcha with `AWS_REGION`?
AdvancedConceptboto3 & AWS automation
Answer
Order: explicit region_name, then AWS_DEFAULT_REGION, then the region in the active profile in ~/.aws/config. boto3 does not read AWS_REGION (that is the variable the Lambda runtime and several other AWS SDKs use), so scripts that set only AWS_REGION failed with botocore.exceptions.NoRegionError: You must specify a region. In CI, aws-actions/configure-aws-credentials sets both. Our habit: pass region_name explicitly for multi-region code, and set AWS_DEFAULT_REGION for single-region scripts.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?BeginnerWhat are waiters, and why use them instead of `sleep` loops?Intermediate