aws-sdk-ruby icon indicating copy to clipboard operation
aws-sdk-ruby copied to clipboard

Feature request: pre-populate Aws.config from environment

Open jonathanhefner opened this issue 4 years ago • 9 comments

Issue description

Would it be feasible to pre-populate Aws.config from the runtime environment? For example, if ENV["AWS_REGION"] is set (and non-empty), then by default Aws.config[:region] == ENV["AWS_REGION"]. Likewise for any settings picked up from "~/.aws" or elsewhere.

This would enable in-app configuration code like the following:

Aws.config[:region] ||= "us-east-1"

Where a reasonable default is provided, but can overridden from the outside, without code modification.

Additionally, it may be useful when one wants to test what config values are being picked up from the environment, for example, when debugging.

Gem name ('aws-sdk', 'aws-sdk-resources' or service gems like 'aws-sdk-s3') and its version

aws-sdk

Version of Ruby, OS environment

any

Code snippets / steps to reproduce

N/A

jonathanhefner avatar Aug 30 '19 19:08 jonathanhefner

I think this feature already included. Here is the documentation https://github.com/aws/aws-sdk-ruby#configuration. Let me know if I missed anything. @jonathanhefner @cjyclaire

sivagollapalli avatar May 01 '20 13:05 sivagollapalli

I don't think so.

mamuller@4c327598178f:~/workplace/aws-sdk-ruby$ gems/aws-sdk-resources/bin/aws-v3.rb -v
Aws> s3.config.region # region loaded from ~/.aws/config
=> "us-west-2"
Aws> Aws.config[:region] ||= "us-east-1" # expect this to be us-west-2 and not us-east-1
=> "us-east-1"
Aws> Aws.config[:region]
=> "us-east-1"

mullermp avatar May 01 '20 15:05 mullermp

This may be a tricky one to implement. I would think that whatever configuration is resolved from the credential provider would need to be merged (or overwritten? unsure) into the Aws.config hash.

mullermp avatar May 01 '20 15:05 mullermp

We could implement it by using a block for defaults on Aws.config eg, when defining it:

# lib/aws-sdk-core.rb

@config = Hash.new { |hash, key| hash[key] = Aws.shared_config.send(key) if Aws.shared_config.respond_to?(key) }

I'm a little wary of making changes to default behavior of Aws.config though.

alextwoods avatar May 01 '20 15:05 alextwoods

Marking as needs-major-version for now.

mullermp avatar May 01 '20 19:05 mullermp

We could implement it by using a block for defaults on Aws.config eg, when defining it:

# lib/aws-sdk-core.rb

@config = Hash.new { |hash, key| hash[key] = Aws.shared_config.send(key) if Aws.shared_config.respond_to?(key) }

I'm a little wary of making changes to default behavior of Aws.config though.

@alextwoods Above code works.

Question here is, what If ~/.aws/config default region value is different from ENV['AWS_REGION'] then which value should it pick it up? @mullermp

sivagollapalli avatar May 02 '20 06:05 sivagollapalli

It should prefer ENV over everything else. https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html#aws-ruby-sdk-setting-credentials

mullermp avatar May 04 '20 17:05 mullermp

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] avatar May 05 '21 00:05 github-actions[bot]

Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.

github-actions[bot] avatar May 06 '22 00:05 github-actions[bot]