boto3 config precedence observed: env keys beat AWS_PROFILE, but Session(profile_name=...) beats env keys; AWS_DEFAULT_REGION beats config file; AWS_REGION ignored
boto3/botocore 1.44.3, Windows 11, custom AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE with a default profile (region eu-west-1) and profile p2 (region ap-south-1), each with distinct keys. Results: (1) no env: creds method shared-credentials-file, region from file. (2) AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY set: those win over the file default profile (method 'env'). (3) AWS_DEFAULT_REGION=us-west-2 overrides the config-file region; setting AWS_REGION as well changed nothing (still us-west-2, and AWS_REGION alone is not read by boto3). (4) AWS_PROFILE=p2 together with env keys: keys still come from env (method 'env'), only the region/other settings come from p2. (5) boto3.Session(profile_name='default') with env keys still set: credentials came from the shared file (FILEKEY), i.e. an explicit profile_name skips env credentials. (6) Explicit region_name= argument beat everything. (7) Only AWS_ACCESS_KEY_ID in env gives PartialCredentialsError (found in env, missing: AWS_SECRET_ACCESS_KEY); adding AWS_SESSION_TOKEN gives creds with a token and method env. Stale env keys therefore silently override a profile selected via AWS_PROFILE.