Skip to content

API Gateway emulator builds incomplete APIGatewayProxyRequest; AspNetCoreServer NREs on null Path / RequestContext / headers #2566

Description

@msmourao

Describe the bug

When invoking an ASP.NET Core Lambda through Lambda Test Tool v2 API Gateway emulator, the emulator builds an APIGatewayProxyRequest that is incomplete compared with a real API Gateway event:

  • RequestContext is often null / missing (no Path, HttpMethod, ApiId, Identity, etc.)
  • In some paths, Path, HttpMethod, or path-parameter / header values can be null

Amazon.Lambda.AspNetCoreServer (APIGatewayProxyFunction.MarshallRequest / path + header utilities) assumes these fields are present and throws NullReferenceException (or fails marshalling) instead of degrading safely.

This breaks the local inner loop for ASP.NET Core on Lambda behind the emulator, even when the route is a normal Lambda integration (not an HTTP proxy backend).

Regression Issue

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

Expected Behavior

  • Emulator-built proxy events should populate a minimal but valid RequestContext (and Path / HttpMethod), similar to API Gateway test-invoke.
  • Amazon.Lambda.AspNetCoreServer should null-guard Path, path parameters, and header values so incomplete events fail clearly or use safe defaults, not NRE.

Current Behavior

Marshalling crashes or misbehaves when the emulator omits RequestContext / leaves path or header values null.

Reproduction Steps

  1. Run Lambda Test Tool v2 with API Gateway emulator enabled.
  2. Configure a route to an ASP.NET Core function using Amazon.Lambda.AspNetCoreServer (APIGatewayProxyFunction / Hosting).
  3. Call the route via the emulator HTTP URL (REST or HTTP API mode).
  4. Observe NRE / marshalling failure when RequestContext or Path is null on the synthesized event.

Minimal observation: deserialize/inspect the event the emulator sends to the Runtime API and compare with a real API Gateway proxy event — RequestContext is missing on the emulator path.

Possible Solution

  1. Test Tool emulator: always set APIGatewayProxyRequest.RequestContext (and Path / HttpMethod) when translating HTTP → Lambda event.
  2. AspNetCoreServer: null-safe marshalling for Path, HttpMethod, path parameters, and multi/single-value headers.

We have a working fix on a fork (happy to open a PR once this issue exists).

Additional Information/Context

  • Packages: Amazon.Lambda.AspNetCoreServer, Amazon.Lambda.TestTool (v2 API Gateway emulator)
  • Related (separate feature request): HTTP proxy integration so non-Lambda backends share the emulator origin — not this bug.

AWS .NET SDK and/or Package version used

Amazon.Lambda.AspNetCoreServer 10.2.1
Amazon.Lambda.AspNetCoreServer.Hosting 2.2.1
Amazon.Lambda.TestTool 0.15.1
Amazon.Lambda.Core 3.3.0
Amazon.Lambda.APIGatewayEvents 3.0.1

Targeted .NET Platform

.NET 10, AspNetCoreServer 10.2.1

Operating System and version

Windows 11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions