Skip to content

Commit 53505a0

Browse files
authored
Prefer AWS_REGION over AWS_DEFAULT_REGION in credential fetching (#715)
As https://docs.aws.amazon.com/sdkref/latest/guide/feature-region.html#feature-region-sdk-compat describes, the AWS CLI v2 uses AWS_REGION before AWS_DEFAULT_VERSION.
1 parent 05a11b5 commit 53505a0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/fog/aws/credential_fetcher.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def fetch_credentials(options)
2121
if options[:use_iam_profile]
2222
begin
2323
role_data = nil
24-
region = options[:region] || ENV["AWS_DEFAULT_REGION"]
24+
region = options[:region] || ENV["AWS_REGION"] || ENV["AWS_DEFAULT_REGION"]
2525

2626
if ENV["AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"]
2727
connection = options[:connection] || Excon.new(CONTAINER_CREDENTIALS_HOST)

tests/credentials_tests.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,23 @@
151151
end
152152

153153
ENV["AWS_DEFAULT_REGION"] = "us-west-1"
154+
ENV["AWS_REGION"] = nil
154155

155-
tests('#fetch_credentials with regional STS endpoint with region in env') do
156+
tests('#fetch_credentials with regional STS endpoint with AWS_DEFAULT_REGION in env') do
157+
returns(
158+
aws_access_key_id: 'dummykey',
159+
aws_secret_access_key: 'dummysecret',
160+
aws_session_token: 'dummytoken',
161+
region: 'us-west-1',
162+
sts_endpoint: "https://sts.us-west-1.amazonaws.com",
163+
aws_credentials_expire_at: expires_at
164+
) { Fog::AWS::Compute.fetch_credentials(use_iam_profile: true) }
165+
end
166+
167+
ENV["AWS_DEFAULT_REGION"] = "us-west-2"
168+
ENV["AWS_REGION"] = "us-west-1"
169+
170+
tests('#fetch_credentials with regional STS endpoint with AWS_REGION in env') do
156171
returns(
157172
aws_access_key_id: 'dummykey',
158173
aws_secret_access_key: 'dummysecret',
@@ -165,6 +180,7 @@
165180

166181
ENV["AWS_STS_REGIONAL_ENDPOINTS"] = nil
167182
ENV["AWS_DEFAULT_REGION"] = nil
183+
ENV["AWS_REGION"] = nil
168184
ENV['AWS_WEB_IDENTITY_TOKEN_FILE'] = nil
169185

170186
storage = Fog::Storage.new(

0 commit comments

Comments
 (0)