Rendral

Stack · AWS Lambda

Generate PDFs in AWS Lambda

Running headless Chrome in Lambda is the classic sharp edge: a ~50MB binary layer that eats your deployment budget, cold starts measured in seconds, memory tuned to 1536MB or more just to survive, and a /tmp directory that fills up. Every Chrome or Lambda runtime bump means rebuilding the layer.

An HTTPS call has none of those properties. Your function stays small and fast, memory stays at whatever your own code needs, and the rendering happens on infrastructure that is already warm.

01Call it from AWS Lambda

render.ts
// handler.mjs — Node.js 20+ runtime, no layers required
export const handler = async (event) => {
  const html = renderInvoice(JSON.parse(event.body));

  const res = await fetch("https://rendral.com/api/v1/pdf", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.RENDRAL_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      html,
      options: { format: "A4", pageNumbers: true },
    }),
  });

  if (!res.ok) throw new Error("render failed: " + res.status);

  const pdf = Buffer.from(await res.arrayBuffer());

  return {
    statusCode: 200,
    headers: { "Content-Type": "application/pdf" },
    body: pdf.toString("base64"),
    isBase64Encoded: true,
  };
};

Frequently asked

Do I still need chrome-aws-lambda or @sparticuz/chromium?

No. Those exist to squeeze a Chrome build under the Lambda size limit. With a hosted renderer your function ships only your own code.

What about the 15-minute timeout?

Not a factor for a single render, which takes seconds. For large batches, use async: true and a webhook so the function returns immediately instead of waiting.

How does this affect cold starts?

Substantially. A Chrome layer adds seconds of cold start and forces high memory settings; a fetch call adds neither.

Is it cheaper?

Usually. Lambda bills GB-seconds, and Chrome forces both high memory and long durations. A small function that waits on HTTP is a much cheaper shape.

Related

Start rendering in minutes.

A free tier, five endpoints, and SDKs for Node and Python.