API Gateway emulator builds incomplete APIGatewayProxyRequest; AspNetCoreServer NREs on null Path / RequestContext / headers
- Lingua principale
- C#
- Stelle
- 1.7k
- Fork
- 503
- Merge medio
- 1g 18h
- PR unite (30g)
- 21
Descrizione
### 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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia esaminando la traduzione degli eventi HTTP-to-Lambda dell’emulatore API Gateway di Lambda Test Tool v2 e confronta il suo evento con un vero evento proxy di API Gateway. Poi traccia APIGatewayProxyFunction.MarshallRequest di Amazon.Lambda.AspNetCoreServer e le relative utilità per percorsi e header. Il lavoro è completato quando gli eventi incompleti dell’emulatore non causano più NRE né errori di marshalling, con una gestione sicura dei campi null elencati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- aws, csharp
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100