Design High-Performing Architectures

A company serves a global website through Amazon CloudFront. On every viewer request, lightweight JavaScript must rewrite the URL and add a header based on request headers. The logic needs no network calls and does not read the request body, and it must run at edge locations with sub-millisecond startup and the lowest cost at millions of requests per second. Which solution should the company use?

Show the answer

Correct answerB. CloudFront Functions on the viewer request event

AWhy not this: Lambda@Edge can modify viewer requests, but it has longer startup and higher cost than needed for lightweight header and URL logic.

BWhy this is right: CloudFront Functions run sub-millisecond JavaScript on viewer events at edge locations at high scale and low cost.

CWhy not this: An origin-side function runs only on requests that reach the origin, not at the edge on every viewer request.

DWhy not this: Global Accelerator routes traffic to endpoints over the AWS global network; it does not run request-manipulation code.

CloudFront Functions run lightweight JavaScript on viewer request and viewer response events at CloudFront edge locations, start in under a millisecond, scale to millions of requests per second, and cost less than Lambda@Edge. Lambda@Edge also runs on viewer requests but suits heavier logic that needs network access, the request body, or origin events, at higher latency and cost.