Skip to content

Object reference not set to an instance of an object when proxying from API Gateway #1987

@samprakos

Description

@samprakos

Describe the bug

I have a simple "Hello world" lambda (c#) that works when invoking it via a function url. However, once I try to invoke it via API Gateway (lambda integration), I get "Object reference not set to an instance of an object" from APIGatewayHttpApiV2ProxyFunction.MarshallRequest.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Messages from API Gateway are processed properly.

Current Behavior

Null reference error

Reproduction Steps

  1. Create a lambda using the attached zip
  2. Run dotnet lambda deploy-function from the project directory
  3. Navigate to the function in AWS Console, create a Function URL
  4. Invoke the lambda using the Function URL from a browser (should see "Hello from AWS Lambda!")
  5. Copy the Lambda ARN so you can map an API Gateway "proxy" call to it.
  6. Got API Gateway, create a REST API.
  7. Map a resource as a "proxy" resource.
  8. Add an "ANY" method to the resource.
  9. Configure the "ANY" method to proxy calls to the lambda ARN
  10. Test the call using the "Test" tab, a GET to the root of the API
  11. Should get "Object reference not set to an instance of an object" error.

I've tried setting up the lambda using services.AddAWSLambdaHosting(LambdaEventSource.RestApi); and services.AddAWSLambdaHosting(LambdaEventSource.RestApi) and services.AddAWSLambdaHosting(LambdaEventSource.HttpApi)...same result.

TodoApi.zip

Possible Solution

No suggestions...but the stack trace I get doesn't include file line numbers...that would be helpful. The stacktrace I get is this:

2025-02-19T20:03:33.732Z	7af2e7e1-d232-4fb4-a1b6-882286c3dd37	fail	System.NullReferenceException: Object reference not set to an instance of an object.
   at Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayHttpApiV2ProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)
   at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2.FunctionHandlerAsync(TREQUEST request, ILambdaContext lambdaContext)
   at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass26_0`2.<<GetHandlerWrapper>b__0>d.MoveNext()
--- End of stack trace from previous location ---

Additional Information/Context

Here is how I set up the Integration request for my api gateway method. I have tried setting "Lambda proxy integration" to true and false...same result.

Image

AWS .NET SDK and/or Package version used

Amazon.Lambda.AspNetCoreServer.Hosting version 1.7.3
Dotnet 8

Targeted .NET Platform

.net 8

Operating System and version

x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.module/aspnetcore-supportp3This is a minor priority issueresponse-requestedWaiting on additional info and feedback. Will move to close soon in 7 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions