It's a Friday afternoon, and the pass route a developer, call them Sam, built on their laptop has just been deployed to AWS Lambda for the first time. Locally it signs a ticket in a few hundred milliseconds. In production, the first request returns a 502, and the log has one line in it: EROFS: read-only file system, open '/var/task/out/ticket-4471.pkpass'.
Sam fixes the path and points it at /tmp. The next request gets further and dies on spawn openssl ENOENT. The library they picked signs by calling the openssl binary, and the Lambda runtime image doesn't ship one. By the time that is solved there's a third problem waiting: the three certificate files they pasted into environment variables don't fit.
None of this is exotic. It's what happens when code designed for a server with a disk, a shell and a generous config meets a runtime that has none of them. This guide walks through what each serverless platform actually takes away, and how to sign a .pkpass entirely in memory so none of it matters.
What a serverless function takes away from you
Every platform is a little different, and the differences decide which of your existing code survives.
AWS Lambda mounts your code read-only. The one writable path is /tmp, which you can size anywhere from 512 MB to 10,240 MB. Reading files you bundled with the function works fine. Writing next to them is what throws EROFS.
Vercel Functions on the Node.js runtime behave much the same way. The filesystem is read-only, /tmp gives you up to 500 MB of scratch space, and files you write there belong to one function instance. A second instance serving the next request can't see them.
Cloudflare Workers never had a disk at all. With a recent compatibility date, node:fs now exists, but it's a virtual filesystem. Your bundle sits read-only under /bundle, and /tmp is memory-backed and unique to each request. Anything you write there counts against the 128 MB memory limit of the isolate and vanishes when the request ends.
So across all three, you can read what you shipped and you can scribble somewhere temporary. What you can't do is treat the disk as a place where state lives between requests. You also can't assume any binary beyond your own runtime is installed, and on an edge runtime you can't assume the Node.js crypto module is there either. What every one of them does give you is Web Crypto.
Where pass libraries reach for the disk
A .pkpass is a zip archive holding pass.json, a set of images, a manifest.json of SHA-1 hashes and a detached PKCS#7 signature over that manifest. If you want the full anatomy, the manifest and signature walkthrough covers every byte. The format itself never needs a filesystem. Plenty of libraries use one anyway, in four places:
- Certificates as paths. The constructor takes
certPathandkeyPathrather than strings or bytes, so the key has to exist as a file somewhere. - A model directory. Images and a template
pass.jsonare read from a folder at request time. That one is fine in Lambda and Vercel if the folder is bundled, and a problem on Workers. - Temp files for the zip. The archive is assembled in a working directory, then read back to send. That's the
EROFSSam hit. - Shelling out to
openssl. Signing runsopenssl smimeas a child process, passing file paths and often the certificate password on the command line. The Python guide shows exactly how that fails in a container without the binary.
The fourth is the one with no workaround inside the function. You can bundle files and you can write to /tmp, but on Workers there is no process to spawn, and on Lambda you'd be shipping your own OpenSSL build in a layer to keep an old design alive. If a library signs through a subprocess, it doesn't belong in a serverless function.
The Node.js crypto module is a softer version of the same trap. It works on Lambda and on Vercel's Node.js runtime, and Workers now implements most of it behind the nodejs_compat flag. Vercel's edge runtime doesn't have it, which is the edge runtime error Next.js developers run into. A signer written against Web Crypto doesn't care which of these it lands on.
Getting three PEM files into a function with no files
Signing needs three pieces of material: your Pass Type ID certificate, Apple's WWDR intermediate certificate and your private key. As PEM text they are small but not tiny. An RSA 2048 private key in PKCS#8 form is about 1.7 KB. The WWDR G4 intermediate is about 1.6 KB. Your own certificate usually lands somewhere around 2 KB. Together, you're looking at roughly 5 KB.
That number collides with platform limits in ways that aren't obvious until a deploy fails.
On Lambda, it doesn't fit. Lambda caps all of a function's environment variables at 4 KB in aggregate. Three PEMs blow through that before you've added a database URL. Put them in AWS Secrets Manager instead, which allows 64 KB per secret, as one JSON secret with three fields. Fetch it once when the container starts. Parameter Store works too, but a standard parameter holds 4 KB, so you'd need one parameter per PEM or the advanced tier at 8 KB.
On Workers, each one fits separately. Cloudflare limits each variable or secret to 5 KB, with 64 per Worker on the free plan and 128 on paid. One PEM per secret is comfortable. Three PEMs crammed into one value is not.
On Vercel, it depends on the runtime. Node.js functions get 64 KB of environment variables per deployment, which is plenty. Edge functions and middleware are limited to 5 KB per variable, so the same one-PEM-per-variable rule applies there.
Before any of that, check the key format. Web Crypto imports private keys as PKCS#8 and nothing else. If your PEM starts with -----BEGIN RSA PRIVATE KEY-----, it's PKCS#1 and a Web Crypto runtime will refuse it. Convert it once, on your own machine:
# Pull the certificate and key out of the .p12 you exported from Keychain
openssl pkcs12 -legacy -in pass.p12 -clcerts -nokeys -out pass-cert.pem
openssl pkcs12 -legacy -in pass.p12 -nocerts -nodes -out pass-key.pem
# Rewrite the key as PKCS#8, the only private key format Web Crypto accepts
openssl pkcs8 -topk8 -nocrypt -in pass-key.pem -out pass-key.pkcs8.pem
# Store each one as its own Worker secret
npx wrangler secret put APPLE_PASS_CERT < pass-cert.pem
npx wrangler secret put APPLE_PASS_KEY < pass-key.pkcs8.pem
npx wrangler secret put APPLE_WWDR_CERT < wwdr-g4.pemThe -legacy flag is there because macOS Keychain still encrypts exported .p12 files with RC2-40, which OpenSSL 3 no longer loads by default. Without it, the first command fails with an "unsupported" error that looks like a wrong password. The system openssl on a Mac is LibreSSL and may not know the flag, so run this with a current OpenSSL build. Where the canonical copy should live after that is its own question, answered in where to store your signing certificate.
Images belong in the bundle
Every pass needs at least an icon, and most carry a logo and a strip or thumbnail. These are static. They don't change per holder, so there's no reason to load them from anywhere at request time.
On Lambda and Vercel's Node.js runtime, reading a file you bundled is allowed. Read it once at module scope, outside the handler, and every warm request reuses the bytes. The read-only filesystem only objects to writes.
On Workers, import the image as a module. Wrangler can bundle any file as raw bytes if you add a rule for it:
# wrangler.toml
[[rules]]
type = "Data"
globs = ["**/*.png"]An import of ./assets/icon@2x.png then hands you an ArrayBuffer, baked into the deployed script. There's no fetch to fail and no bucket for someone to tidy up later.
If your images do vary, say a logo per tenant on a multi-brand platform, fetch them from object storage and keep a small in-memory cache keyed by tenant. Don't write them to /tmp as a cache. On Workers it's wiped every request, and on Lambda it's per container, so you'd pay the fetch anyway and add cleanup on top.
The whole route, in memory from request to response
Here is a complete Worker that signs an event ticket and returns it, using the open-source passmint package. It's built on Web Crypto, with no node:* imports and no Buffer, so the same code runs on Workers, Vercel Edge, Deno, Bun and Node 20 or later.
import { Pass, SigningMaterial } from "passmint"
import icon from "./assets/icon@2x.png"
interface Env {
APPLE_PASS_CERT: string
APPLE_WWDR_CERT: string
APPLE_PASS_KEY: string
}
// Importing the key is the expensive step, so do it once per isolate.
let material: Promise<SigningMaterial> | undefined
function signingMaterial(env: Env) {
material ??= SigningMaterial.fromPem({
signerCertPem: env.APPLE_PASS_CERT,
wwdrPem: env.APPLE_WWDR_CERT,
privateKeyPkcs8Pem: env.APPLE_PASS_KEY,
}).catch((err) => {
material = undefined
throw err
})
return material
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const ticketId = new URL(request.url).searchParams.get("ticket")
if (!ticketId) return new Response("Missing ticket", { status: 400 })
const signed = await Pass.eventTicket({
passTypeIdentifier: "pass.com.example.event",
serialNumber: ticketId,
teamIdentifier: "ABCD1234EF",
organizationName: "Example Events",
description: "Concert ticket",
images: { icon: { x2: { bytes: new Uint8Array(icon) } } },
barcodes: [{ format: "qr", message: ticketId }],
})
.primaryField({ key: "event", label: "Event", value: "Spring Tour" })
.sign(await signingMaterial(env))
return signed.toResponse()
},
}Nothing touches a disk. The PEMs arrive as strings, the icon arrives as bytes, the zip is assembled in memory and toResponse() returns a standard Response with Content-Type: application/vnd.apple.pkpass and an attachment disposition already set. The .catch that resets the cached promise matters more than it looks: without it, one failed import caches the failure for the life of the isolate.
On Lambda, the shape is the same, with two changes. The PEMs come from Secrets Manager instead of the environment, and the response has to be base64 encoded, because a Lambda handler returns JSON, not a stream of bytes.
import { readFile } from "node:fs/promises"
import { GetSecretValueCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager"
import { Pass, SigningMaterial } from "passmint"
const icon = await readFile(new URL("./assets/icon@2x.png", import.meta.url))
const material = new SecretsManagerClient({})
.send(new GetSecretValueCommand({ SecretId: process.env.PASS_SIGNING_SECRET_ID }))
.then(({ SecretString }) => {
const pem = JSON.parse(SecretString!)
return SigningMaterial.fromPem({
signerCertPem: pem.cert,
wwdrPem: pem.wwdr,
privateKeyPkcs8Pem: pem.key,
})
})
export const handler = async (event: { queryStringParameters?: Record<string, string> }) => {
const ticketId = event.queryStringParameters?.ticket
if (!ticketId) return { statusCode: 400, body: "Missing ticket" }
const signed = await Pass.eventTicket({
passTypeIdentifier: "pass.com.example.event",
serialNumber: ticketId,
teamIdentifier: "ABCD1234EF",
organizationName: "Example Events",
description: "Concert ticket",
images: { icon: { x2: { bytes: new Uint8Array(icon) } } },
barcodes: [{ format: "qr", message: ticketId }],
})
.primaryField({ key: "event", label: "Event", value: "Spring Tour" })
.sign(await material)
return {
statusCode: 200,
headers: {
"Content-Type": "application/vnd.apple.pkpass",
"Content-Disposition": `attachment; filename="${ticketId}.pkpass"`,
},
body: Buffer.from(await signed.toUint8Array()).toString("base64"),
isBase64Encoded: true,
}
}Forget isBase64Encoded and the phone receives a page of base64 text instead of a pass, and Wallet never gets a chance to open it. If you sit behind an API Gateway REST API rather than a Function URL or an HTTP API, you also have to register application/vnd.apple.pkpass as a binary media type, or the gateway mangles the bytes on the way out.
A worked example: the ticket route that ran out of room
Consider a representative small ticketing platform, based on an anonymized example. Their pass route ran on Lambda behind an HTTP API, and it worked from launch. The certificate, key and WWDR intermediate were each base64 encoded into an environment variable and decoded into /tmp at the start of every request, because the library they used wanted file paths.
The first sign of trouble wasn't a crash. It was a failed deploy, months later, when someone added an error tracking DSN to the function's environment. Lambda refused the configuration change because the variables now exceeded 4 KB in total. Base64 had inflated three PEMs by about a third, and the team had been running within a few hundred bytes of the cap without knowing a cap existed.
The workaround they reached for first made things worse. They squeezed the key and certificate back into a single base64 .p12 variable to save space, with the password beside it. That deployed. It also meant decoding a .p12 and writing two PEM files into /tmp on every request. Lambda reuses warm containers, so those files sat in /tmp between invocations, and a later code path that wrote passes to the same directory filled it during a busy on-sale. The function began failing with ENOSPC at exactly the moment traffic peaked.
The fix took an afternoon. They moved the three PEMs into one Secrets Manager secret, fetched it once at container start, and switched to a library that took PEM strings and returned bytes. Signing stopped touching /tmp entirely. The function's environment dropped back to a handful of small variables, and the ENOSPC errors disappeared because nothing was being written.
None of their failures came from signing being hard. Each one came from treating a function like a server, with config kept in files and a disk trusted to hold things between requests.
Cold starts, CPU limits and what to do once
Serverless billing and limits push you toward doing expensive work once per instance, not once per request. For pass signing, the expensive part is parsing the PEMs and importing the private key. Producing one RSA signature over a small manifest is cheap by comparison.
That's why both examples above hold the SigningMaterial at module scope. On Lambda, a warm container keeps it between invocations. On Workers, an isolate keeps it across the requests it serves, and the passmint documentation recommends exactly this.
Workers adds a CPU budget to think about. The free plan allows 10 ms of CPU time per request, while the paid plan defaults to 30 seconds and can go to 5 minutes. A cold isolate importing a key and signing on its first request uses more CPU than a warm one signing alone. If you're on the free plan and see the occasional exceeded CPU limit error on a cold start, that's the likely cause, and the paid plan's default leaves plenty of headroom.
Two things you should not cache. Don't cache the signed pass at the CDN, because a cached response serves one holder's ticket to the next person who asks. The Next.js guide has a full account of that going wrong. And don't cache across tenants. If you sign for several Pass Type IDs, key the material cache by identifier so a request for one brand can never pick up another's certificate.
When the function shouldn't hold the key at all
Everything above assumes your function signs. That's a reasonable choice for one product and one Pass Type ID. It gets less reasonable as more functions need to issue passes, because each one becomes a place your private key lives, and each one is a place you have to update when the certificate is renewed next year.
The alternative is to keep the key out of your infrastructure entirely. A function that calls a pass API with an API key needs no PEMs, no PKCS#8 conversion, no Secrets Manager and no binary response handling. It sends JSON and gets back a URL to hand the holder, which also works from any runtime with fetch. The certificate, the WWDR intermediate and the expiry date become someone else's job, and the update web service that keeps an installed pass current comes with it.
So the decision comes down to this. If you want to own signing, pick a library that works in memory, put each PEM where the platform's limits allow it and import the key once per instance. If you'd rather your functions never see a private key, Passmint holds the certificate, signs the pass and returns a link, and the quickstart gets a first pass onto a phone without an Apple Developer account.
Primary sources
Common questions
Technical content writer, Passmint
Julio is a technical content writer at Passmint. He writes about Apple PassKit, the Google Wallet API, and what breaks when wallet passes meet production traffic.
More from Julio Song →