Screenshot API on AWS Lambda & Serverless 2026

Deploy SnapAPI screenshot capture to AWS Lambda, Vercel Edge Functions, Cloudflare Workers, and Google Cloud Functions. Full serverless integration examples.

Start Free — 200 screenshots/month

Why Screenshot APIs Are Ideal for Serverless

Running Playwright or Puppeteer on AWS Lambda is famously difficult — the Chromium binary exceeds Lambda's deployment package size limits, requires custom Lambda layers, consumes significant memory, has slow cold starts, and breaks on Lambda runtime updates. Screenshot APIs solve this entirely by moving the browser to a managed external service, leaving the Lambda function as a lightweight HTTP client that calls the SnapAPI REST endpoint and returns the result. A Lambda function that calls SnapAPI fits in a standard Node.js Lambda deployment package, starts in milliseconds, and uses minimal memory — the heavy browser work happens on SnapAPI's infrastructure, not in the Lambda execution environment. This architecture enables serverless screenshot workflows that scale to zero between requests, cost nothing when idle, and scale to handle traffic spikes by invoking additional Lambda instances in parallel, each making concurrent SnapAPI calls within the plan's rate limit.

AWS Lambda Screenshot API with Node.js

Define an AWS Lambda function handler in Node.js or TypeScript that accepts an API Gateway event, extracts the target URL from the query string parameters, calls the SnapAPI client using the installed SDK, and returns the screenshot bytes in a Lambda proxy response. Initialize the SnapAPI client outside the handler function at module scope so that the client is reused across Lambda invocations within the same execution environment, avoiding client re-initialization overhead on warm invocations. Return the screenshot PNG bytes base64-encoded in the Lambda proxy response body with isBase64Encoded set to true and Content-Type set to image/png, enabling API Gateway to decode and proxy the binary response correctly to the HTTP client.

import { SnapApiClient } from '@snapapi/client';
const client = new SnapApiClient({ apiKey: process.env.SNAPAPI_KEY! });

export const handler = async (event: any) => {
  const url = event.queryStringParameters?.url;
  if (!url) return { statusCode: 400, body: JSON.stringify({ error: 'url required' }) };

  const result = await client.screenshot({ url, fullPage: true, width: 1280 });
  return {
    statusCode: 200,
    headers: { 'Content-Type': 'image/png' },
    body: result.image.toString('base64'),
    isBase64Encoded: true,
  };
};

Vercel Edge Functions Screenshot API

Vercel Edge Functions running on the Vercel Edge Network use the fetch-based Web API rather than Node.js APIs, making the SnapAPI integration a standard fetch call to the SnapAPI REST endpoint. Define an Edge Function in app/api/screenshot/route.ts using the Edge Runtime export, read the URL from the request URL search params, call the SnapAPI REST endpoint using the fetch API with the Authorization header set to the API key, and return the response image bytes as a NextResponse with Content-Type image/png. Edge Functions run close to the user on Vercel's global edge network, reducing the round-trip latency for screenshot API calls that are initiated by user interactions — though the SnapAPI call itself runs from the edge node's location, so edge proximity primarily reduces the function invocation latency rather than the SnapAPI screenshot generation time. Use Vercel's KV store for caching screenshot results at the edge, returning cached images for repeat URL requests without invoking SnapAPI on every edge function call.

Cloudflare Workers Screenshot API

Cloudflare Workers running on Cloudflare's global network call SnapAPI using the native fetch API available in the Workers runtime. Define a Worker that handles GET requests with a url query parameter, calls the SnapAPI REST endpoint using fetch with the SNAPAPI_KEY secret bound to the Worker, and returns a Response with the screenshot bytes and the Content-Type: image/png header. Use Cloudflare's Cache API to cache screenshot responses at the Cloudflare edge, keyed by the target URL, so that repeated screenshot requests for the same URL are served from the nearest Cloudflare PoP cache without making additional SnapAPI calls. Cloudflare Workers KV provides a global key-value store for persisting screenshot metadata — the target URL, the capture timestamp, and the storage key — across all Cloudflare edge locations, enabling distributed screenshot result lookup in Workers deployed globally without a centralized database.

Google Cloud Functions Screenshot API

Google Cloud Functions using the Node.js runtime call SnapAPI using the official JavaScript SDK or the native https module, with the API key stored in Google Cloud Secret Manager and accessed via the Functions framework's built-in Secret Manager integration. Define an HTTP-triggered Cloud Function that reads the URL from the request query parameters, calls the SnapAPI client initialized at module scope for connection reuse across warm invocations, and writes the screenshot PNG to Google Cloud Storage using the @google-cloud/storage client before returning the GCS object URL in the response. Configure the Cloud Function with 256MB of memory — sufficient for the Node.js process and the SnapAPI HTTP call without the browser memory overhead that Puppeteer-in-Lambda requires — and a timeout of thirty seconds to accommodate SnapAPI screenshot generation for complex pages. Use Cloud Scheduler to trigger the Cloud Function on a schedule for batch screenshot monitoring workflows, passing a list of monitored URLs in the scheduler job payload for the function to process in sequence within a single invocation.

Serverless Screenshot API Architecture Patterns

Serverless screenshot architectures using SnapAPI follow a common pattern regardless of the specific serverless platform: an event source triggers the function, the function calls SnapAPI via HTTP, and the function stores the result in object storage or a database before returning. The event source varies by use case — an API Gateway HTTP request for on-demand screenshot APIs, a scheduled event for periodic monitoring, an SQS or EventBridge message for asynchronous processing, or a storage event for pipeline-triggered captures. Because SnapAPI handles the browser, the function code is purely an HTTP client and storage client, eliminating the Chromium dependency that makes traditional serverless screenshot implementations complex. This clean separation of concerns makes serverless screenshot functions easy to test locally, portable across serverless platforms, and straightforward to extend with pre- and post-processing steps like URL validation, result transformation, and webhook notification without modifying the core screenshot capture logic.

Serverless Screenshot API Cost Optimization

Serverless screenshot architectures have two cost components: the serverless function invocation cost and the SnapAPI screenshot credit cost. Optimizing the total cost requires minimizing unnecessary SnapAPI calls and right-sizing the serverless function's memory allocation to the actual requirements of the HTTP client workload. Because the function no longer runs a Chromium browser, the memory required for a screenshot function is a fraction of what Puppeteer-in-Lambda requires — 128MB to 256MB is typically sufficient for a Node.js function making SnapAPI HTTP calls and uploading results to S3. At this memory allocation, Lambda's per-invocation cost is minimal, and the primary cost driver is the SnapAPI plan tier. Implement aggressive caching of SnapAPI results in the serverless architecture — checking S3 for an existing screenshot before calling SnapAPI, and returning the cached result for repeated requests within the cache TTL — to minimize SnapAPI calls and keep costs predictable as the application scales.

Getting Started with Serverless Screenshot API

Deploy your first serverless screenshot function in minutes by starting with the AWS Lambda Node.js example above, replacing the placeholder API key with your SnapAPI key from snapapi.pics, and deploying with the AWS SAM or Serverless Framework CLI. For Vercel and Cloudflare deployments, the function code runs directly in the platform's development environment — vercel dev or wrangler dev — making local testing straightforward before deployment. The free SnapAPI tier with two hundred monthly screenshots is sufficient for testing and low-traffic serverless deployments; upgrade to the starter plan when the deployed function starts receiving production traffic beyond the free tier limit. Monitor function invocation counts and SnapAPI call counts together to maintain the cache hit rate target that keeps costs within budget as serverless screenshot usage scales with application traffic.

Serverless Screenshot API Security Best Practices

Serverless screenshot functions accepting URL parameters from external callers must validate the target URL to prevent SSRF attacks where an attacker passes internal network URLs as the screenshot target. Implement URL validation that rejects non-HTTP schemes, IP address URLs in RFC-1918 private ranges (10.x, 172.16-31.x, 192.168.x), and localhost URLs before passing anything to the SnapAPI client. Store the SnapAPI API key in the platform secret management service -- AWS Secrets Manager, Vercel encrypted environment variables, or Cloudflare Worker secrets -- never hardcoding it in function code or configuration files committed to version control. Rate limit the screenshot endpoint per client IP using API Gateway throttling, Vercel middleware, or Cloudflare rate limiting rules to prevent a single caller from exhausting your monthly SnapAPI credit allocation through rapid automated requests.