This guide walks you through everything you need to go from zero to a working PDF generation endpoint. By the end, you will have cloned the repository, deployed the service to your AWS account using the Serverless framework, and usedDocumentation 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.
curl to convert an HTML snippet into a downloadable PDF file.
Prerequisites
Before you begin, make sure the following tools are installed and configured on your machine:
- AWS account — Sign up here if you don’t already have one. Your IAM user or role must have sufficient permissions to create API Gateway, Lambda, IAM, S3, and CloudFormation resources.
- AWS CLI — Install and configure it with your credentials by following the official instructions. Run
aws sts get-caller-identityto confirm your credentials are active. - Node.js — The Lambda runtime targets Node.js 20.x. We recommend installing and managing Node.js versions with NVM (Node Version Manager).
- Yarn — The project uses Yarn as its package manager. Install it by following the Yarn installation instructions.
- Serverless Framework — Install it globally by following the Serverless installation instructions. The project requires Serverless Framework v3 (
>=3.38.0 <4.0.0).
Clone and Install
Clone the repository from GitHub and install all workspace dependencies from the project root:Yarn uses the workspace configuration defined at the repo root to install dependencies for all packages, including
packages/api. This step installs puppeteer-core, @sparticuz/chromium, and all other runtime and build dependencies.Deploy to AWS
From the project root directory, run the production deployment command:This command runs in two phases:Copy this URL — you will use it in the next step.
- Build phase (
make clean && make all) — Compiles and packages the Chromium v122 binary into the Lambda Layer artifact (layers/chromium-v122.zip). This step requiresmaketo be available in your shell. - Deploy phase (
serverless deploy --stage prod) — The Serverless framework provisions all AWS infrastructure defined inpackages/api/serverless.yml: theHeadlessChromiumLambda Layer, theprintLambda function (Node.js 20.x, 2,048 MB memory, 30-second timeout), and the API Gateway endpoint.
Convert Your First HTML to PDF
With the service deployed, send your first HTML-to-PDF conversion request using The request body is a JSON object with three fields:
A successful request returns an
curl. Replace {api-identifier} with the actual identifier from your deployment output:| Field | Type | Required | Description |
|---|---|---|---|
html | string | ✅ Yes | The full HTML document to render as a PDF. |
source | string | No | A label identifying the request origin, used in Lambda logs. |
settings | object | No | Puppeteer page.pdf() options such as format, width, height, and margins. |
application/pdf binary response, which curl writes directly to my-document.pdf.Verify the Output
Open
my-document.pdf in any PDF viewer (Preview on macOS, Adobe Reader, your browser, etc.) and confirm the document renders correctly. You should see a page with the heading Hello World and the paragraph text Converted from HTML to PDF.If the file is empty or the command returned an error response, check the following:- Confirm the endpoint URL and stage name are correct.
- Run
aws sts get-caller-identityto verify your AWS credentials are still active. - Check the Lambda function logs in the AWS Console under CloudWatch → Log Groups →
/aws/lambda/serverless-pdf-generator-prod-printfor detailed error messages.
What’s Next
Now that your service is live, explore the rest of the documentation to configure, extend, and integrate the PDF generator:Configuration
Customize Lambda memory, timeout, CORS settings, and S3 large-response handling.
POST /print Reference
Full API reference for the
/print endpoint including all request parameters and error codes.Architecture
Deep-dive into how API Gateway, Lambda, the Chromium Layer, and S3 fit together.
Large Responses
Learn how the service handles PDFs that exceed API Gateway’s 10 MB response limit via S3 offloading.