AWS CloudFront Functions

Sub-millisecond JS at CloudFront edge. Lighter than Lambda@Edge, narrower scope.

VISIT AWS CLOUDFRONT FUNCTIONS

Key takeaway: Reach for this only inside AWS, and only for the narrow band of work it covers: rewriting headers, URIs, cookies, and query strings on the way past. Within that band it is faster and cheaper than Lambda@Edge with no cold start at all. It is never a reason to adopt CloudFront, because Cloudflare Workers covers the same ground with a full runtime and outbound network access.

Quick facts

  • CategoryCDN-attached function
  • LanguageJS (subset)
  • PricingPaid
  • LicenseProprietary
  • Created2021
  • GitHub starsclosed
  • Cold startinstant
  • PoPs~600
  • Node-compatNo

What it is

CloudFront Functions runs lightweight JavaScript at CloudFront PoPs in sub-millisecond time. Restricted runtime, no full V8, smaller API surface than Workers. Used for header manipulation, URL rewriting, simple auth checks. Cheaper than Lambda@Edge, narrower scope.

Best for

  • AWS-locked teams needing fast header / URL manipulation at edge
  • Cost-sensitive AWS edge workloads (cheaper than Lambda@Edge)
  • Simple viewer-request transformations

When not to pick it

Skip CloudFront Functions for anything beyond simple transformations, the runtime is restricted. For serious edge logic, Lambda@Edge or Cloudflare Workers.

My take

Niche but useful inside AWS. Outside that ecosystem, Cloudflare Workers covers the same use cases with a richer runtime.

A deliberately small runtime

CloudFront Functions is not V8 with restrictions applied. It is a purpose-built JavaScript engine with a small API surface, running on every CloudFront point of presence with no execution environment to create and therefore no cold start line on your latency chart. The restrictions are absolute rather than tunable: no outbound network calls, no filesystem, no access to request or response bodies, no npm. What you can do is inspect and rewrite headers, URIs, cookies, and query strings, issue a redirect, and perform a cheap signature or token check. That is the complete list. The hard boundary is a feature rather than an oversight, because it makes it impossible for anyone on your team to put slow work in front of every request. The moment you find yourself wanting to call an API from inside one of these, you have outgrown the tool and Lambda@Edge is the next step up.

Where it sits against Lambda@Edge and Workers

Inside AWS the split is clean and worth writing into your own standards document: CloudFront Functions on viewer request and viewer response for cheap transforms, Lambda@Edge on origin triggers or anywhere real compute is required. Per-invocation cost is a fraction of Lambda@Edge, so pushing every eligible transform down is a straightforward saving on a high-traffic property, and there is no cold start to reason about. Outside AWS the comparison is far less flattering. Cloudflare Workers does everything CloudFront Functions does and then keeps going, with real fetch, storage bindings, and a full V8 runtime at comparable latency, on a network you can sign up for in minutes. So the correct framing is narrow: this is a good tool once CloudFront is already your delivery layer, and irrelevant to the platform decision itself.

Frequently asked questions

What can CloudFront Functions actually do?

Header manipulation, URI rewrites and redirects, cookie inspection, query-string normalisation, and simple token or signature checks on the viewer request or response. It cannot make network calls, read request or response bodies, use npm packages, or touch a filesystem. Anything beyond a cheap transform of the request line and headers needs Lambda@Edge instead.

Are CloudFront Functions cheaper than Lambda@Edge?

Yes, meaningfully. Per-invocation cost is a fraction of Lambda@Edge and there is no execution environment or cold start to pay for. On a high-traffic property that gap is the main argument for moving every eligible viewer-request transform down to CloudFront Functions and reserving Lambda@Edge for work that genuinely needs a full runtime.

CloudFront Functions or Cloudflare Workers?

If CloudFront is already your CDN, use CloudFront Functions for the transforms it covers. If you are choosing fresh, Cloudflare Workers handles the same job with a full V8 runtime, outbound fetch, and storage bindings at comparable latency and with self-serve onboarding, so adopting CloudFront purely for its functions makes little sense.

Links

Compare AWS CloudFront Functions side-by-side

Similar tools you should also consider

If AWS CloudFront Functions is your pick, the next conversation is short

The 30-min call is where your edge runtime choice becomes a real architecture, an integration plan with your data layer + auth + build pipeline, and a price range you can take to your stakeholders.