Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

region set in profile in $HOME/.aws/config is ignored #3305

Open
olfek opened this issue Apr 27, 2024 · 7 comments
Open

region set in profile in $HOME/.aws/config is ignored #3305

olfek opened this issue Apr 27, 2024 · 7 comments
Assignees
Labels
bug This issue is a bug. credentials

Comments

@olfek
Copy link

olfek commented Apr 27, 2024

Describe the bug

region set in profile in $HOME/.aws/config IS NOT loaded in.

Expected Behavior

region set in profile in $HOME/.aws/config IS loaded in.

Current Behavior

region set in profile, in $HOME/.aws/config
loaded into Amazon.Runtime.CredentialManagement.CredentialProfile.Region
IS NOT CONSIDERED in Amazon.Runtime.ClientConfig.get_RegionEndpoint.

Reproduction Steps

N/A

Possible Solution

region set in profile, in $HOME/.aws/config
loaded into Amazon.Runtime.CredentialManagement.CredentialProfile.Region
SHOULD BE CONSIDERED in Amazon.Runtime.ClientConfig.get_RegionEndpoint.

Just like how:

endpoint_url set in profile, in $HOME/.aws/config
loaded into Amazon.Runtime.CredentialManagement.CredentialProfile.EndpointUrl
IS CONSIDERED in Amazon.Runtime.ClientConfig.get_ServiceURL.

Additional Information/Context

N/A

AWS .NET SDK and/or Package version used

3.7.30X.XX

Targeted .NET Platform

.NET 7

Operating System and version

Windows 11

@olfek olfek added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 27, 2024
@olfek olfek changed the title region set in profile in $HOME/.aws/config region set in profile in $HOME/.aws/config is ignored Apr 27, 2024
@bhoradc bhoradc self-assigned this Apr 29, 2024
@bhoradc bhoradc added credentials and removed needs-triage This issue or PR still needs to be triaged. labels Apr 29, 2024
@bhoradc
Copy link

bhoradc commented Apr 29, 2024

Hi @olfek,

Thank you for submitting the issue. Using latest .NET SDK and Package version, I unable to reproduce the scenario you mentioned.

Can you please review below steps and let me know if I am missing anything? Or kindly assist in providing steps to reproduce the issue.

  • ~/.aws/config file has test profile
[test]
region=us-west-2
  • Executed below program
using Amazon.Runtime.CredentialManagement;
using Amazon.S3;

            var credentialsFile = new SharedCredentialsFile(@"C:\Users\**\.aws\config");

            CredentialProfile profile;

            if (credentialsFile.TryGetProfile("test", out profile))
            {
                Console.WriteLine("Profile Region: " + profile.Region.SystemName);
                var s3Client = new AmazonS3Client(profile.Region);
                Console.WriteLine("Region Endpoint: " + s3Client.Config.RegionEndpoint);
            }
  • Execution result
Profile Region: us-west-2
Region Endpoint: US West (Oregon) (us-west-2)

Regards,
Chaitanya

@bhoradc bhoradc added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 29, 2024
@olfek
Copy link
Author

olfek commented Apr 30, 2024

@bhoradc ...

I believe your understanding is different to what this issue is about.

  1. You explicitly read the config file.
    I am expecting the config file to be read implicitly by the ClientConfig code like this - https://github.com/aws/aws-sdk-net/blob/cd07e59f0a3317f7fad9f14f4eefc0aff8596aaa/sdk/src/Core/Amazon.Runtime/ClientConfig.cs#L310C1-L317C26
  2. You explicitly pass the region to the client constructor.
    I am expecting the region to be set implicitly using the implicitly read config file, like this -
    this.ServiceURL = profile.EndpointUrl;

Keep in mind using the RegionEndpoint or ServiceURL setters will nullify each other. In the case of profiles in the external config file, I think the SDK code should trust it to be valid and load it in as is without any additional validation/cleanup logic. So perhaps this line (

this.ServiceURL = profile.EndpointUrl;
) should be this.(s)erviceURL = profile.EndpointUrl and similarly this.(r)egionEndpoint = profile.Region.

@normj
Copy link
Member

normj commented Apr 30, 2024

@olfek How are you configuring the SDK to use a specific profile? There a few cases with the .NET SDK doesn't know what profile is being used because it is working with the low level primitives like credentials. In those cases it falls back to looking for configuration with the default profile or the profile the AWS_PROFILE environment variable is set to.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 1, 2024
@olfek
Copy link
Author

olfek commented May 1, 2024

@normj --- I've set the AWS_PROFILE environment variable, this is my $HOME/.aws/config file:

[profile localstack]
region = eu-west-2
endpoint_url = http://localhost:4566

endpoint_url is loaded in, but region is not.

I'm using https://github.com/localstack/localstack by the way.

@normj
Copy link
Member

normj commented May 6, 2024

@olfek The SDK either has the region or the endpoint_url set with the last one set overruling the previous. In this case the endpoint_url from config is being set on the client config last causing the region to be cleared out. What are you expecting with having both the region and endpoint_url set?

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 7, 2024
@olfek
Copy link
Author

olfek commented May 8, 2024

@normj ---

What are you expecting with having both the region and endpoint_url set?

I'm expecting the ability to use a specific region with LocalStack, configured outside of code, to facilitate multi-region services.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. credentials
Projects
None yet
Development

No branches or pull requests

4 participants