soto-core icon indicating copy to clipboard operation
soto-core copied to clipboard

Read default region from `~/.aws/config`

Open adam-fowler opened this issue 3 years ago • 3 comments

Steps

  • Add default region to AWSClient.
  • Read environment variable AWS_DEFAULT_REGION or value in ~/.aws/config. Will need to take into account AWS_PROFILE environment variable. Might need to do something to sync with ConfigFileCredentialProvider
  • To ensure this is done before any requests are made, need to do this before the credential provider setup is complete
  • If a service config has no region then should use default region from AWSClient.
  • As service can be created before AWSClient we cannot just copy default region to service. One way to avoid this is add new region useDefault which will use AWSClient default when a request occurs.

adam-fowler avatar May 05 '21 15:05 adam-fowler

Question that comes to mind:

  • Since all services require an AWSClient, could we move the region to the client, and remove it from the services?

AWSClient would get the default region from ~/.aws/config using the profile from the credentials provider, if ConfigFileCredentialProvider was used. Otherwise, region would default to us-east-1. Users would be able to pass a region to AWSClient the same way they pass it to services today.

If the above worked, there would be no longer need to have region in the services, right? Would this be a valid/acceptable approach?

eneko avatar May 07 '21 04:05 eneko

Question that comes to mind:

* Since all services require an `AWSClient`, could we move the region to the client, and remove it from the services?

Couple of reasons why we might not want to do this. 1) It is a breaking change, would need a new major version 2) Currently accessing a different region is a simple process which just involves creating a new version of the service ( which is a cheap operation ). Creating a new AWSClient is an expensive operation. Credential acquisition can take time. Also if you have a credentials that need refreshing having multiple AWSClients would mean you are doing this work multiple times.

adam-fowler avatar May 07 '21 06:05 adam-fowler

Makes sense, thanks for clarifying.

eneko avatar May 17 '21 21:05 eneko