feat: allow the AWS_DEFAULT_REGION environment variable (#721)
Amazon has this variable documented, and apparently people are trying to
use it, so we should support it
diff --git a/google/auth/aws.py b/google/auth/aws.py
index b362dd3..c2b521c 100644
--- a/google/auth/aws.py
+++ b/google/auth/aws.py
@@ -424,9 +424,9 @@
The logic is summarized as:
- Retrieve the AWS region from the AWS_REGION environment variable or from
- the AWS metadata server availability-zone if not found in the
- environment variable.
+ Retrieve the AWS region from the AWS_REGION or AWS_DEFAULT_REGION
+ environment variable or from the AWS metadata server availability-zone
+ if not found in the environment variable.
Check AWS credentials in environment variables. If not found, retrieve
from the AWS metadata server security-credentials endpoint.
@@ -504,8 +504,8 @@
)
def _get_region(self, request, url):
- """Retrieves the current AWS region from either the AWS_REGION
- environment variable or from the AWS metadata server.
+ """Retrieves the current AWS region from either the AWS_REGION or
+ AWS_DEFAULT_REGION environment variable or from the AWS metadata server.
Args:
request (google.auth.transport.Request): A callable used to make
@@ -526,6 +526,10 @@
if env_aws_region is not None:
return env_aws_region
+ env_aws_region = os.environ.get(environment_vars.AWS_DEFAULT_REGION)
+ if env_aws_region is not None:
+ return env_aws_region
+
if not self._region_url:
raise exceptions.RefreshError("Unable to determine AWS region")
response = request(url=self._region_url, method="GET")