Don Sartain
Don Sartain

Reputation: 617

Null Reference Exception from APIGatewayProxyFunction

I finally managed to get my API into a state where I can upload it to AWS Lambda, and then I get the error below whenever I try to use the API Gateway to test it.

{
  "errorType": "AggregateException",
  "errorMessage": "One or more errors occurred. (Object reference not set to an instance of an object.)",
  "stackTrace": [
    "at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)",
    "at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
    "at lambda_method(Closure , Stream , Stream , ContextInfo )"
  ],
  "cause": {
    "errorType": "NullReferenceException",
    "errorMessage": "Object reference not set to an instance of an object.",
    "stackTrace": [
      "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayProxyRequest apiGatewayRequest)",
      "at Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction.<FunctionHandlerAsync>d__12.MoveNext()"
    ]
  }
}

code:

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
    protected override void Init(IWebHostBuilder builder)
    {
        try
        {
            builder
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseStartup<Startup>()
                .UseApiGateway();
        }
        catch (Exception ex)
        {
            LambdaLogger.Log("Exception throw in LambdaEntryPoint: " + ex);
        }
    }
}

I don't get any exceptions logged from my Startup or LambdaEntryPoint. I'm really new to AWS, so I'm not sure what else to check.

Any ideas on this one?

Upvotes: 6

Views: 7272

Answers (2)

Edward Olamisan
Edward Olamisan

Reputation: 891

check box "Use Lambda Proxy integration" in api gateway method helped me for .net 6 web api.

configuration screenshot

Upvotes: 0

Kirkaiya
Kirkaiya

Reputation: 1264

This may be the same issue that someone from AWS has addressed with someone else on the AWS github repo for AWS .NET Lambda integration: https://github.com/aws/aws-lambda-dotnet/issues/168

Upvotes: 2

Related Questions