Call Snapshot Site from a Lambda handler
The handler resolves a known page and uses an explicit client abort budget rather than packaging a browser.
const pages = {
pricing: "https://example.com/pricing",
docs: "https://example.com/docs",
};
export const handler = async (event) => {
const url = pages[event.pageId];
if (!url) throw new Error("Unknown page");
const response = await fetch(
"https://api.prod.ss.snapshot-site.com/api/v1/screenshot",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-snapshotsiteapi-key": process.env.SNAPSHOT_SITE_API_KEY,
},
body: JSON.stringify({
url,
format: "webp",
width: 1440,
height: 900,
fullSize: true,
}),
signal: AbortSignal.timeout(45_000),
},
);
if (!response.ok) {
throw new Error(`Capture failed: ${response.status}`);
}
return await response.json();
};
