---
type: Integration Guide
title: "AWS (CloudFront + Lambda@Edge) prerendering integration"
description: "Run prerender bot detection at CloudFront edge using Lambda@Edge — fits sites already on AWS that want native AWS infrastructure end-to-end."
resource: "https://prerendering.com/integrations/aws"
tags: [integration, aws (cloudfront + lambda@edge)]
timestamp: 2026-05-11T00:00:00Z
---

# AWS (CloudFront + Lambda@Edge) prerendering integration

Run prerender bot detection at CloudFront edge using Lambda@Edge — fits sites already on AWS that want native AWS infrastructure end-to-end.

Lambda@Edge runs at CloudFront edge locations, similar to Cloudflare Workers but inside the AWS ecosystem. The pattern is identical: detect crawlers in the viewer-request handler, rewrite to a prerender origin (S3-cached HTML, an ECS-hosted Chromium service, or an external prerender API).

## Best for

- Sites already on AWS (S3 + CloudFront, ECS, ALB)
- Teams with AWS-only compliance constraints
- Architectures where prerender output is cached in S3

## Setup

Attach a Lambda@Edge function to the CloudFront distribution at the viewer-request stage. The function inspects user-agent, optionally verifies bot identity, and rewrites the request URI or origin to point to the prerender source.

```js
// Full example: https://github.com/ostr-io/ostrio-docs/tree/master/docs/prerendering/examples/aws-lambda
function handler(event) {
  const request = event.request;
  const headers = request.headers || {};
  const ua = getHeader(headers, 'user-agent');
  const shouldRoute = shouldPrerender(request);

  headers[PRERENDER_HEADER] = { value: shouldRoute ? '1' : '0' };

  if (shouldRoute && ua) {
    headers[UA_HEADER] = { value: ua };
  } else {
    delete headers[UA_HEADER];
  }

  return request;
}
```

## Fits when

- Existing infrastructure is on AWS and you want vendor-uniform deployment.
- Prerender snapshots can be cached in S3 (low-volatility content).
- You have AWS-side compliance or data-residency constraints.

## Avoid when

- You need rapid iteration on the bot-routing logic (Lambda@Edge cold-deploy is slow).
- A managed prerender service would be faster to ship and you can pay external for it.

## Common pitfalls

- **Lambda@Edge size and runtime limits** — Viewer-request Lambda@Edge has a 1MB function-size limit and a 5-second timeout. Keep the function lean — bot detection only, no rendering. Heavy logic moves to the prerender origin.
- **CloudFront cache key not including user-agent** — By default, CloudFront does not cache by user-agent. If the bot path serves different HTML, configure a cache policy that varies on a derived header (e.g., x-is-bot) set by the Lambda. Otherwise bots and humans get the same cached HTML.
- **Slow Lambda@Edge cold starts** — Cold-start latency adds 200-500ms per request. Use Lambda Provisioned Concurrency for the viewer-request layer if traffic justifies it.

## Related

- [Redirect Bot Traffic to Prerendering](/blog/redirect-bot-traffic-to-prerendering.md)
