Skip to content

add aws-lambda-compressed #819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2025
Merged

Conversation

sommeeeer
Copy link
Contributor

Closes #475

For some apps you might get a 413 when your response body is too large. This is a limitation in Lambda. In you AWS console you will get this error message:
[ERROR] [xxxxxxxxx] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 413.

The default limit in Lambdas is 6mb for invocation payloads (synchronous request/response). You can read more about its limitations here

This PR introduces a new wrapper called aws-lambda-compressed that will compress the response body by default if the client sends a request with a supported encoding in the Accept-Encoding header. Compression will be applied in the following priority order: br (Brotli) → gzipdeflate. If none of these is found, we just return the body as is.

After some testing on various bodies of reasonable size (8mb+). I found out that the Lambda will timeout after 10s if we use the default BROTLI_PARAM_QUALITY which is 11. Its also the highest. Therefore defaulting it to 6 is probably wise, as a compromise.

An environment variable BROTLI_QUALITY makes this configurable.

Copy link

changeset-bot bot commented Apr 8, 2025

🦋 Changeset detected

Latest commit: e1a54cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch
app-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Apr 8, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/@opennextjs/aws@819

commit: e1a54cc

@sommeeeer sommeeeer marked this pull request as draft April 9, 2025 13:55
@sommeeeer sommeeeer marked this pull request as ready for review April 9, 2025 17:28
@sommeeeer sommeeeer requested a review from conico974 April 9, 2025 17:28
Copy link
Contributor

@conico974 conico974 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks

@conico974 conico974 merged commit 997b392 into opennextjs:main Apr 10, 2025
3 checks passed
@github-actions github-actions bot mentioned this pull request Apr 7, 2025
@sommeeeer sommeeeer deleted the compressed-wrapper branch April 10, 2025 08:10
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.

Re-enable nextjs compression or allow enabling it optionally
2 participants