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:
Source of problem:
config.RegionEndpoint = options.Region;
Workaround:
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());
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.
Hi,
I'm still getting the exception below when my class tries to resolve the service IAmazonRekognition via DI.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Amazon.Runtime.AmazonClientException: No RegionEndpoint or ServiceURL configured
at Amazon.Runtime.ClientConfig.Validate() in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\ClientConfig.cs:line 472
at Amazon.Runtime.AmazonServiceClient..ctor(AWSCredentials credentials, ClientConfig config) in D:\JenkinsWorkspaces\trebuchet-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\AmazonServiceClient.cs:line 154
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Amazon.Extensions.NETCore.Setup.ClientFactory.CreateClient(Type serviceInterfaceType, AWSCredentials credentials, ClientConfig config) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\extensions\src\AWSSDK.Extensions.NETCore.Setup\ClientFactory.cs:line 103
at Amazon.Extensions.NETCore.Setup.ClientFactory.CreateServiceClient(ILogger logger, Type serviceInterfaceType, AWSOptions options) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\extensions\src\AWSSDK.Extensions.NETCore.Setup\ClientFactory.cs:line 90
I'm using the following nuget packages:
I also have set the environment variables as stated in the docs:
The @imkheong 's workaround is working ;)
Also ran into this issue recently. I was able to fix it by setting the AWS_REGION along with AWS_DEFAULT_REGION environment variable as well.
Most helpful comment
Also ran into this issue recently. I was able to fix it by setting the AWS_REGION along with AWS_DEFAULT_REGION environment variable as well.