Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run wkhtmltopdf on AWS Lambda by shipping a Linux-compatible wkhtmltopdf binary, every shared library it needs, and the fonts your HTML uses. Put those files in a Lambda layer or a container image, match the build to the function’s operating-system generation and CPU architecture, and test the exact package in a Lambda-compatible Linux environment before relying on it in production.

Lambda does not include wkhtmltopdf automatically. The executable is based on QtWebKit, so a desktop download copied into a function commonly fails with missing libraries, an incompatible loader, or unusable fonts.

Choose a deployment model first

Concern ZIP plus layer Container image
Where files live Lambda extracts layer contents under /opt; place the executable in /opt/bin and libraries in /opt/lib. Copy the executable, libraries, fonts, and application code into the image.
Best fit Several functions share one tested wkhtmltopdf bundle. You need a reproducible operating-system image or many native dependencies.
Build Create a Linux ZIP with preserved executable bits and library paths. Build from an AWS Lambda base image and deploy the resulting image.
Updates Publish a new layer version and attach it to functions. Rebuild and redeploy when the base image or bundled dependencies change; AWS does not update your image for you.
Architecture The layer must match the function’s x86_64 or arm64 architecture. The image and native binary must match the selected architecture.

AWS documents both approaches. Its layer guidance says content must be built in Linux because Lambda functions run on Amazon Linux, and that attached layers are loaded into /opt: Packaging your layer content. AWS also documents container-image deployments: Creating Lambda container images.

Confirm the runtime and architecture

Check the function’s Runtime and Architecture settings before building. AWS Lambda supports x86_64 and arm64, but a binary built for one is not a universal binary for the other. A community AL2023 layer example defaults to x86_64; treat that package as an example to validate, not as an AWS-supported compatibility guarantee.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Amazon Linux 2 reached end of life on June 30, 2026, according to AWS’s runtime guidance. Prefer an Amazon Linux 2023-based runtime where your application supports it, and re-check AWS’s current runtime table because deprecation dates are projections that can change: Lambda runtimes.

Build a ZIP layer

1. Create a Linux build environment

Build inside a Linux host or Docker image comparable to the target Lambda runtime. Do not download a macOS or desktop Linux executable and assume it will run in Lambda. Keep separate artifacts for each architecture and runtime family when their loaders or libraries differ.

2. Assemble the layer layout

layer/               # directory that will be zipped
├── bin/
│   ├── wkhtmltopdf
│   └── wkhtmltopdf-wrapper
├── lib/              # Qt, WebKit, graphics and other required .so files
├── fonts/            # fonts used by your documents
└── etc/fonts/        # optional fontconfig configuration

Lambda extracts this tree as /opt. Set executable permissions before zipping:

chmod 755 layer/bin/wkhtmltopdf layer/bin/wkhtmltopdf-wrapper
(cd layer && zip -r ../wkhtmltopdf-layer.zip .)

3. Inspect native dependencies

Run ldd on the binary in the same Linux environment used to build it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ldd layer/bin/wkhtmltopdf

For every library reported as “not found,” add a compatible copy under layer/lib or rebuild against libraries present in the Lambda base environment. Also verify the dynamic loader itself. Copying one missing file at a time from an unrelated distribution can create subtle symbol-version failures; a reproducible build image is safer.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

4. Configure a wrapper for libraries and fonts

A wrapper gives the function one stable command and makes environment setup explicit:

#!/bin/sh
set -eu
export LD_LIBRARY_PATH="/opt/lib:${LD_LIBRARY_PATH:-}"
export FONTCONFIG_PATH="/opt/etc/fonts"
export FONTCONFIG_FILE="/opt/etc/fonts/fonts.conf"
exec /opt/bin/wkhtmltopdf "$@"

Save it as layer/bin/wkhtmltopdf-wrapper. If you use a different font directory, adjust the variables and confirm that fontconfig can see it. A community AL2023 example bundles DejaVu fonts and graphics libraries; its exact RPM and dependency set must be rebuilt or validated for your selected runtime and architecture.

5. Publish and attach the layer

  1. In the Lambda console, open Layers, choose Create layer, upload wkhtmltopdf-layer.zip, and select the compatible architectures.
  2. Open your function, choose Layers, select Add a layer, and attach the version you published.
  3. Invoke /opt/bin/wkhtmltopdf-wrapper from code, not a relative path.

You can publish the same artifact with the AWS CLI, then attach the returned layer version to a function. Keep the layer ZIP and build manifest in source control so a new version is reproducible.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Invoke wkhtmltopdf from a Lambda function

The example below is a Python handler. It writes HTML to /tmp, runs the wrapper, and returns a base64-encoded PDF. Increase the function’s ephemeral storage if documents or temporary images are large.

import base64
import os
import subprocess
import tempfile

def lambda_handler(event, context):
    html = event.get("html", "<html><body><h1>Hello Lambda</h1></body></html>")
    with tempfile.TemporaryDirectory(dir="/tmp") as work:
        source = os.path.join(work, "input.html")
        output = os.path.join(work, "output.pdf")
        with open(source, "w", encoding="utf-8") as f:
            f.write(html)
        result = subprocess.run(
            ["/opt/bin/wkhtmltopdf-wrapper", "--quiet", source, output],
            capture_output=True, text=True, timeout=60
        )
        if result.returncode != 0:
            raise RuntimeError(f"wkhtmltopdf failed ({result.returncode}): {result.stderr[-2000:]}")
        with open(output, "rb") as f:
            pdf = base64.b64encode(f.read()).decode("ascii")
    return {
        "statusCode": 200,
        "headers": {"Content-Type": "application/pdf"},
        "isBase64Encoded": True,
        "body": pdf
    }

For production, validate and constrain any user-supplied HTML or URLs. wkhtmltopdf can make network requests while rendering; do not expose an unrestricted URL-to-PDF endpoint without SSRF controls, timeouts, and outbound-network policy.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use a Lambda container image instead

Container images are useful when the dependency tree is too large or awkward for a layer. Start with the AWS base image for your language and runtime, copy in a binary built for that image’s Amazon Linux generation and architecture, then copy libraries and fonts into known paths.

# Dockerfile (illustrative Python Lambda image)
FROM public.ecr.aws/lambda/python:3.12
COPY bin/wkhtmltopdf /opt/bin/wkhtmltopdf
COPY bin/wkhtmltopdf-wrapper /opt/bin/wkhtmltopdf-wrapper
COPY lib/ /opt/lib/
COPY fonts/ /opt/fonts/
COPY app.py ${LAMBDA_TASK_ROOT}/app.py
RUN chmod 755 /opt/bin/wkhtmltopdf /opt/bin/wkhtmltopdf-wrapper
ENV LD_LIBRARY_PATH=/opt/lib
ENV FONTCONFIG_PATH=/opt/etc/fonts
CMD ["app.lambda_handler"]

Build and test the image for the same architecture you configure in Lambda. AWS base images include Amazon Linux system libraries and the Lambda runtime interface client; they do not include wkhtmltopdf. When AWS publishes base-image updates, rebuild and redeploy your image after validating the native bundle again.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate before production traffic

  • Run /opt/bin/wkhtmltopdf-wrapper --version in a container or deployed test function.
  • Render a document containing normal text, non-Latin characters, web fonts, images, CSS, and a long page.
  • Inspect the PDF for missing glyphs, blank images, incorrect page breaks, and clipped content.
  • Check CloudWatch logs for loader errors, fontconfig warnings, timeouts, and non-zero exit codes.
  • Test cold starts and warm invocations separately; native startup and font discovery happen inside the function environment.
  • Exercise the exact architecture, runtime generation, memory size, timeout, and network configuration used in production.

Troubleshooting common failures

cannot open shared object file

Cause: a Qt, WebKit, graphics, or system library is absent, or LD_LIBRARY_PATH does not include its directory. Fix: run ldd in the matching build environment, include every missing compatible library, and invoke the wrapper with an absolute path.

Exec format error

Cause: an x86_64 executable is running in an arm64 function, or vice versa. Fix: rebuild for the configured architecture and publish an architecture-specific layer or image.

Fonts are missing or substituted

Cause: Lambda has no guarantee that the fonts on your workstation exist in the runtime, or fontconfig cannot find the bundled directory. Fix: package the required fonts, set FONTCONFIG_PATH and (when needed) FONTCONFIG_FILE, and test characters from every supported script.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

The process exits with a generic non-zero status

Cause: malformed HTML, an inaccessible remote asset, an unsupported feature, or a killed process. Fix: capture stderr, render a minimal local HTML file, add an explicit timeout, and then reintroduce external assets one at a time.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The PDF is blank or pages are incomplete

Cause: JavaScript has not finished, resources are blocked by networking, or the function timed out. Fix: make the HTML self-contained where possible, allow outbound access only when required, increase timeout and memory, and use wkhtmltopdf’s documented load-delay or JavaScript options carefully.

It works locally but not in Lambda

Cause: different glibc/loader versions, missing fonts, permissions, architecture, or environment variables. Fix: reproduce inside the target Lambda base image rather than copying the local installation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Operational and cost considerations

Lambda billing depends on invocation duration, memory, and other AWS account settings; wkhtmltopdf’s rendering time varies with HTML size, JavaScript, images, and remote requests. Set a timeout below your caller’s deadline and queue large jobs when synchronous responses are impractical. Write temporary files only under /tmp, remove them after each render, and remember that warm environments can retain temporary data between invocations.

Cache immutable layers or images through your deployment pipeline, not inside the function. Record the wkhtmltopdf build, source package, OS family, architecture, dependency list, and font set. Re-test after changing any of them. There is no official AWS guarantee that a particular community layer or RPM remains compatible with every future runtime.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Or skip the browser setup

If your requirement is simply a reliable screenshot or PDF of a web page, ScreenshotNeo provides a hosted API and MCP server instead of asking you to maintain a native browser stack. One request can return PNG, JPEG, WebP, or PDF. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; those cleanup steps can be disabled individually. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the page verdict and billing status.

For a direct PDF or image request, see the ScreenshotNeo API documentation:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. Every plan includes its capture options; the Free plan provides 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Can I attach an x86_64 wkhtmltopdf layer to an arm64 Lambda?

No. The native executable and its libraries must be built for the function’s selected architecture; publish separate artifacts when you support both.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does an AWS Lambda base image already contain wkhtmltopdf?

No. AWS base images provide the Lambda runtime components and Amazon Linux libraries, but you must add wkhtmltopdf, its native dependencies, and fonts.

Where can Lambda write intermediate HTML and PDF files?

Use the writable /tmp directory. The deployment package and mounted layers are not writable at invocation time.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.