aws / aws-dotnet-extensions-configuration

This repository hosts various libraries that help developers configure .NET applications using AWS services.

Home Page:https://aws.amazon.com/developer/language/net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

appsettings.json element AWS:Region:DefaultRegion results in crash

ExcaliburVT opened this issue · comments

Description

We are utilizing the library from AWS GovCloud. This behavior may not reproduce in AWS Commerical.

Reproduction Steps

Please reference: aws/aws-lambda-dotnet#832

But the short answer was that if the appsettings.json contained the default that apparently gets overwritten during a 'dotnet lambda package` command the AWS:Region:DefaultRegion element was causing a crash.

Example appsettings.json:

{
  "Lambda.Logging": {
    "IncludeCategory": false,
    "IncludeLogLevel": false,
    "IncludeNewline": true,
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Information"
    }
  },
  "AWS": {
    "Region": "DefaultRegion"
  }
}

Logs

An exception was thrown when the constructor for type 'XXXXX.LambdaEntryPoint' was invoked. Check inner exception for more details.: LambdaException


   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
Name or service not known: HttpRequestException
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Extensions.Configuration.SystemsManager.Internal.SystemsManagerProcessor.GetParametersByPathAsync()
   at Amazon.Extensions.Configuration.SystemsManager.Internal.SystemsManagerProcessor.GetDataAsync()
   at Amazon.Extensions.Configuration.SystemsManager.SystemsManagerConfigurationProvider.LoadAsync(Boolean reload)
   at Amazon.Extensions.Configuration.SystemsManager.SystemsManagerConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2.Start()
   at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2..ctor(StartupMode startupMode)
   at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2..ctor()
   at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction..ctor()
   at XXXXX.LambdaEntryPoint..ctor()
Name or service not known: SocketException
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)

[WARN] (invoke@invoke.c:331 errno: Address family not supported by protocol) run_dotnet(dotnet_path, &args) failed

Resolution

I was able to avoid the crash by manually overriding the DefaultRegion value with our actual region

Environment Variable:

Key: AWS__Region
Value:


This is a 🐛 bug-report

Hi @ExcaliburVT,

Good afternoon.

I don't think this is a Systems Manager issue. As you mentioned in the other issue aws/aws-lambda-dotnet#832, AWS CodeBuild is modifying appsettings.json with the region set to DefaultRegion, which is causing the exception. The next steps are more about investigating if this is an issue with AWS .NET Lambda extensions or CodeBuild. Not sure what analysis could be done with Systems Manager extensions library since it is merely respecting the configured values in appsetings.json. Closing this issue since it is a duplicate of aws/aws-lambda-dotnet#832.

Thanks,
Ashish

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Is DefaultRegion a catch-all that should work anywhere? Even if the cli problem is considered the primary one I would still wish for the library to give a better error. It took me hours of trial and error to figure out what the root cause was. @ashishdhingra

Is DefaultRegion a catch-all that should work anywhere? Even if the cli problem is considered the primary one I would still wish for the library to give a better error. It took me hours of trial and error to figure out what the root cause was. @ashishdhingra

@ExcaliburVT From what I have observed, the DefaultRegion is set in appsettings.json, when an application is generated from Visual Studio template. You might want to check if there are multiple appsettings.<environment>.json files in your code solution which might be the cause of issue.