API Gateway emulator builds incomplete APIGatewayProxyRequest; AspNetCoreServer NREs on null Path / RequestContext / headers
- Dominant language
- C#
- Stars
- 1.7k
- Forks
- 503
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 18
Description
### 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
Contributor guide
Research direction
Start by inspecting the Lambda Test Tool v2 API Gateway emulator's HTTP-to-Lambda event translation and compare its event with a real API Gateway proxy event. Then trace Amazon.Lambda.AspNetCoreServer's APIGatewayProxyFunction.MarshallRequest and its path and header utilities. Done means incomplete emulator events no longer cause NREs or marshalling failures, with safe handling for the listed null fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100