'Okta SDK error with .Net Core 3.1 on AWS Serverless Lambda

I am getting an error when using Okta OpenIDConnect, with .Net Core 3.1 - deployed on AWS serverless Lambda.

It works perfectly fine but when I publish and test on AWS, it fails with the following exception:

An exception was thrown when the constructor for type 'WebCore.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)
**path: ArgumentException**
   at Okta.Sdk.Abstractions.Configuration.Providers.Yaml.YamlConfigurationExtensions.AddYamlFile(IConfigurationBuilder builder, String path, Boolean optional)
   at Okta.Sdk.OktaClient.GetConfigurationOrDefault(OktaClientConfiguration apiClientConfiguration)
   at Okta.Sdk.OktaClient..ctor(OktaClientConfiguration apiClientConfiguration, IOAuthTokenProvider oAuthTokenProvider, HttpClient httpClient, ILogger logger, IRetryStrategy retryStrategy, ISerializer serializer)
   at Okta.Sdk.OktaClient..ctor(OktaClientConfiguration apiClientConfiguration, ILogger logger, ISerializer serializer, IOAuthTokenProvider oAuthTokenProvider)
   at OktaMiddlewareExtension.AddOktaAuthentication(IServiceCollection services, IConfiguration configuration, Boolean useGroups) in D:\Documents\Dev---\OktaMiddlewareExtension.cs:line 55
   at WebCore.Startup.ConfigureServices(IServiceCollection services) in D:\Documents\Dev\---\Startup.cs:line 47
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   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 WebCore.LambdaEntryPoint..ctor()

This is the only error that I can log (even from the inner exception): It just says "path"

Any tips or help highly appreciated!



Solution 1:[1]

Got the problem today, this was due to the environnement variable 'HOME' not set under lambda.

A quick fix for that, before instanciating the okta client :

Environment.SetEnvironmentVariable("HOME", "/tmp");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jérémie Leclercq