Skip to content

Commit ae2bf2e

Browse files
Improve AWS region detection by checking AWS_DEFAULT_REGION as fallback (snowflakedb#2535)
Co-authored-by: Patryk Czajka <patryk.czajka@snowflake.com>
1 parent b301717 commit ae2bf2e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

DESCRIPTION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
1616
- Added an option to exclude `botocore` and `boto3` dependencies by setting `SNOWFLAKE_NO_BOTO` environment variable during installation
1717
- Revert changing exception type in case of token expired scenario for `Oauth` authenticator back to `DatabaseError`
1818
- Added support for pandas conversion for Day-time and Year-Month Interval types
19+
- Fix "No AWS region was found" error if AWS region was set in `AWS_DEFAULT_REGION` variable instead of `AWS_REGION` for `WORKLOAD_IDENTITY` authenticator
1920
- Add `ocsp_root_certs_dict_lock_timeout` connection parameter to set the timeout (in seconds) for acquiring the lock on the OCSP root certs dictionary. Default value for this parameter is -1 which indicates no timeout.
2021

2122
- v3.17.4(September 22,2025)

src/snowflake/connector/wif_util.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ def extract_iss_and_sub_without_signature_verification(jwt_str: str) -> tuple[st
9696

9797
def get_aws_region() -> str:
9898
"""Get the current AWS workload's region, or raises an error if it's missing."""
99-
region = None
100-
if "AWS_REGION" in os.environ: # Lambda
101-
region = os.environ["AWS_REGION"]
102-
else: # EC2
99+
100+
region = os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION")
101+
102+
if not region:
103+
# Fallback for EC2 environments
103104
# TODO: SNOW-2223669 Investigate if our adapters - containing settings of http traffic - should be passed here as boto urllib3session. Those requests go to local servers, so they do not need Proxy setup or Headers customization in theory. But we may want to have all the traffic going through one class (e.g. Adapter or mixin).
104105
region = InstanceMetadataRegionFetcher().retrieve_region()
105106

@@ -108,6 +109,7 @@ def get_aws_region() -> str:
108109
msg="No AWS region was found. Ensure the application is running on AWS.",
109110
errno=ER_WIF_CREDENTIALS_NOT_FOUND,
110111
)
112+
111113
return region
112114

113115

0 commit comments

Comments
 (0)