Skip to content

Return 413 when the ASP.NET Core response exceeds the Lambda payload limit - #2620

Open
pkryusuf wants to merge 1 commit into
aws:masterfrom
pkryusuf:fix-1815-response-too-large
Open

pkryusuf wants to merge 1 commit into
aws:masterfrom
pkryusuf:fix-1815-response-too-large

Conversation

@pkryusuf

Copy link
Copy Markdown

Issue #, if available: #1815

Description of changes:

Following the approach suggested in the issue: when the marshalled response body is larger than the 6 MB Lambda payload limit, APIGatewayProxyFunction and APIGatewayHttpApiV2ProxyFunction now return a 413 (and log an error) instead of the invocation failing with an opaque error. The check runs in MarshallResponse before PostMarshallResponseFeature, so users can still customize the 413 response.

  • Utilities.IsResponseBodyTooLarge: base64 bodies are measured by string length, text bodies by UTF-8 byte count.
  • Change file added for Amazon.Lambda.AspNetCoreServer (patch).
  • Tests: unit tests for the limit boundary (text, base64, multi-byte UTF-8, null) and end-to-end tests for REST and HTTP API v2 using a new 7 MB LargeResponseController in TestWebApp. All 233 tests in Amazon.Lambda.AspNetCoreServer.Test pass on net8.0 and net10.0.

Notes for review:

  • The check covers the body only, not headers or JSON escaping, so a response just under the limit can still fail the old way. Exact checking would mean serializing every response.
  • ALB (1 MB limit) and response streaming are unchanged; happy to add ALB if wanted.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@pkryusuf
pkryusuf requested review from a team as code owners November 21, 2026 18:11

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant