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

Support setting region with Environment variables #494

Closed
imkheong opened this Issue Nov 19, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@imkheong

imkheong commented Nov 19, 2016

Problem:
To use .NET Core AWS SDK on Linux and Docker, I want to set the Region using environement variable instead of relying on credential file.

Expected:
When Region is not set in AWSOptions, it will fall back to use 'AWS_REGION' environment variable to set the region.

Actual:
Amazon.Extensions.NETCore.Setup.ClientFactory.CreateClient would throw an exception "Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured.".

Steps to reproduce:

  1. Remove Region property from appsettings.json.
  2. Initiate any of the service client, e.g. AwsEcsService using default constructor.

Source of problem:

  1. ClientFactory.cs Line 158
    config.RegionEndpoint = options.Region;
    This effectively sets RegionEndpoint to null, at the same time, ClientConfig.cs's probeForRegionEndpoint is set to false, which disables probing from environment variable.

Workaround:

  1. Create AWSOptions object manually (do not use the one in appsettings). Read the Region environment variable and set it to RegionEndpoint.
var region = Environment.GetEnvironmentVariable(EnvironmentVariableAWSRegion.ENVIRONMENT_VARIABLE_REGION);
if (string.IsNullOrEmpty(region))
    throw new ArgumentNullException($"Cannot read '{EnvironmentVariableAWSRegion.ENVIRONMENT_VARIABLE_REGION}' from environment variable.", nameof(region));
services.AddDefaultAWSOptions(new AWSOptions
{
    Region = RegionEndpoint.GetBySystemName(region)
});

Suggestion:
It will be nice to simply set new AWSOptions() without having to read it manually from environment variable like

services.AddDefaultAWSOptions(new AWSOptions());
@normj

This comment has been minimized.

Member

normj commented Nov 21, 2016

Thanks for letting us know about the issue. I just pushed version 3.3.0.2 of AWSSDK.Extensions.NETCore.Setup that fixes the issue so that clients can pick up the region by the environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment