AWS API Gateway enforces a hard maximum response payload size of 10 MB, and Lambda’s own synchronous response limit is 6 MB. Either constraint can be breached when generating PDFs from complex or image-heavy HTML documents. Rather than returning an error, the AWS Lambda PDF Generator handles oversized responses automatically by applying gzip compression first, and falling back to an S3-hosted redirect if compression alone is not sufficient. This two-stage pipeline was introduced in v2.0.0.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/barchart/aws-lambda-pdf-generator/llms.txt
Use this file to discover all available pages before exploring further.
Automatic large-response handling was introduced in v2.0.0. Earlier versions returned an error for any PDF exceeding the API Gateway payload limit.
Response Strategies
Theprint handler registers two response generators before any rendering begins:
Gzip Compression
LambdaResponseGeneratorGzip compresses the PDF binary using gzip before Lambda returns it to API Gateway. For typical HTML-derived PDFs — which contain largely repetitive structured data — compression ratios of 50–80 % are common, frequently bringing a borderline-large PDF well inside the 6 MB Lambda response limit.
The compressed response is returned with the standard Content-Encoding: gzip header. Clients that send an Accept-Encoding: gzip request header will receive and automatically decompress the response. Most HTTP libraries and browsers handle this transparently.
S3 Redirect
LambdaResponseGeneratorS3 is the fallback for PDFs that remain too large after compression. When triggered, the generator:
- Uploads the PDF binary to a configured S3 bucket using
s3:PutObject. - Generates a pre-signed S3 URL that grants temporary read access to the object.
- Returns an HTTP 303 See Other response to the caller with the pre-signed URL in the
Locationheader.
S3 Bucket Configuration
The S3 bucket used byLambdaResponseGeneratorS3 is controlled by two environment variables set in serverless.yml:
| Environment Variable | Default Value | Description |
|---|---|---|
S3_LARGE_HTTP_RESPONSE_REGION | us-east-1 | AWS region where the S3 bucket resides |
S3_LARGE_HTTP_RESPONSE_BUCKET | barchart-aws-lambda-responses | Name of the S3 bucket used to store oversized PDFs |
custom.s3 block in serverless.yml and redeploy:
Client Requirements
For the best results, HTTP clients calling the/print endpoint should be configured as follows:
- Send
Accept-Encoding: gzip— this signals to the service that the client can handle a gzip-compressed response body, enabling the first (and cheaper) large-response strategy. Most modern HTTP clients include this header by default. - Follow HTTP 3xx redirects automatically — if the S3 fallback is triggered, the service returns an HTTP 303. Clients must follow the redirect to retrieve the PDF from S3. The vast majority of HTTP client libraries (including
curl,axios,fetchin browsers, and the AWS SDK) follow redirects automatically; no special configuration is usually needed.
curl command that satisfies both requirements:
--compressed instructs curl to decompress a gzip response automatically. --location enables redirect following for the S3 fallback.