🚀 Ready to transform your cloud infrastructure? Get Started →

CloudFront Functions network calls guide: cf.fetch() and cf.beacon() calling an origin from the CloudFront edge

CloudFront Functions Network Calls: Use cf.fetch() for Real-Time Edge Logic

For years, CloudFront Functions had one hard rule: your edge code could only work with what was already in the request, plus whatever you had stashed in a key value store. The moment your logic needed live data from another service, such as a token revocation list, a fraud score or a user’s plan, you had to move to Lambda@Edge or push that logic back to your origin. On 18 November 2026, AWS announced that Amazon CloudFront Functions now supports network calls, and that rule is gone.

This guide explains how the new cf.fetch() and cf.beacon() methods work, the limits you must design around, what it costs, and practical patterns for authentication, AI agent access control and edge analytics.

What Changed in CloudFront Functions

CloudFront Functions runs lightweight JavaScript at CloudFront edge locations to customise requests and responses. With this launch, a function can send an HTTP request during the viewer request and act on the response before deciding what to do with the viewer’s request. AWS gives two examples in the announcement: checking an AI agent’s permissions and usage budget so that only authorised requests reach your API or MCP server, and sending request signals to a security or fraud detection service to block or challenge bad traffic.

Two helper methods are available from the cloudfront module:

  • cf.fetch() sends a request to an origin and returns a promise that resolves to a response you can read.
  • cf.beacon() sends a request in the background without waiting for a response, which suits analytics events and audit records, even for content served from cache.

Network calls are available at all CloudFront edge locations, and you can use them in both viewer request and viewer response functions.

How CloudFront Functions Network Calls Work

According to the CloudFront Developer Guide, you need a function on JavaScript runtime 2.0 with import cf from "cloudfront"; as the first line. The most important design decision AWS made is this: the destination must be an origin that is already configured on the same distribution. You cannot pass a full URL with a host name. Instead you pass a path and the origin ID, which is the Name field of the origin in the console.

That sounds restrictive, but it is a real advantage. Because the call goes through the origin, it inherits the origin settings you already have:

  • Origin access control (OAC) signs the request with SigV4, so you can call a private S3 bucket or a Lambda function URL without credentials in your code.
  • VPC origins let you call a service in a private subnet that never needs a public endpoint.
  • Connection reuse means CloudFront usually already holds a warm connection, avoiding TCP and TLS setup.
  • Custom origin headers and origin mTLS apply to the call, so shared secrets and client certificates stay in your distribution configuration, not in function code.

The one origin setting that does not carry over is the response timeout. A network call always times out after 1 second.

A fail-closed authorisation example

The pattern below, adapted from the AWS documentation, sends the viewer’s token to an authorisation service and blocks the request if the service rejects it or cannot be reached:

import cf from 'cloudfront';

async function handler(event) {
  const request = event.request;
  const auth = request.headers['authorization'];
  if (!auth) {
    return { statusCode: 401, statusDescription: 'Unauthorized' };
  }
  try {
    const res = await cf.fetch('/v1/authorize', {
      originId: 'auth-service',
      method: 'POST',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify({ token: auth.value, uri: request.uri }),
      includeBody: true,
    });
    if (!res.ok) {
      return { statusCode: 403, statusDescription: 'Forbidden' };
    }
    const result = await res.json();
    request.headers['x-user-id'] = { value: result.userId };
    return request;
  } catch (e) {
    return { statusCode: 503, statusDescription: 'Service Unavailable' };
  }
}

Note two details that trip people up. First, includeBody defaults to false; without it, json() resolves to null. Second, the headers option is a plain object of strings, not the { value: ... } shape used in event.request.headers. Copying the event shape throws an error.

Limits You Must Design Around

The CloudFront quotas page lists the network call limits, and none of them are adjustable:

  • One network call per invocation, with fetch() and beacon() combined. A second call throws, and so does passing two calls to Promise.all().
  • 1 second timeout for the whole call, from sending the request to receiving the last byte.
  • 10 KB maximum request body and 10 KB maximum response body.
  • 10 KB maximum total size of request or response headers, and 8 KB for the path and query string.

There are also platform restrictions. Distributions on the free flat-rate pricing plan do not support network calls. And network calls are not available in the console Test tab or the TestFunction API; in a test, cf.fetch() throws a TypeError, so wrap every call in try/catch or your test will fail.

Fail open or fail closed?

If an error is not caught, CloudFront returns HTTP 503 to the viewer. The documentation lists the errors you should expect: TypeError for invalid calls or unreachable origins, TimeoutError when the 1 second limit is hit, InternalError, and SyntaxError from json(). Decide per use case: security checks should usually fail closed, while personalisation or configuration lookups should fail open so a slow dependency never takes your site down.

Network Calls vs CloudFront KeyValueStore

AWS is clear that network calls do not replace KeyValueStore. Use a network call when the data changes between requests (for example, whether a token has been revoked) or when the dataset is too large for a key value store. Use KeyValueStore for static or slowly changing data such as redirect maps and feature flags, or when you need several lookups per request, because it reads at the edge with no external call. You can combine both: read the active experiment from KeyValueStore, then make one network call to assign a variant.

Pricing

Network calls cost $0.10 per million calls, on top of standard CloudFront Functions invocation charges. They are included at no additional cost in the Pro plan and above in CloudFront flat-rate plans, according to the AWS announcement.

Practical Use Cases

  • Token and session validation: check revocation or entitlements before a request ever reaches your origin.
  • AI agent and MCP gateways: verify an agent’s permissions and remaining budget at the edge, as AWS suggests.
  • Fraud and bot signals: send request attributes to a scoring service and block or challenge risky traffic.
  • Dynamic configuration: read a small JSON object from a private S3 origin protected by OAC.
  • Edge analytics: fire a cf.beacon() for every request, including cache hits, without adding latency. Set logDeliveryErrors: true to see failed beacons in CloudWatch Logs.

Getting Started Checklist

  1. Confirm your distribution is not on the free flat-rate plan.
  2. Add the service you want to call as an origin, with OAC, VPC origin or mTLS as needed, and note its origin ID.
  3. Keep the endpoint fast and close to edge-friendly regions; responses must arrive within 1 second and stay under 10 KB.
  4. Switch the function to JavaScript runtime 2.0, import cloudfront and wrap every call in try/catch.
  5. Test the non-network logic in the console, then roll out to a staging distribution and watch CloudWatch logs and error rates.

Network calls touch your edge security posture, so it is worth reviewing them alongside your wider AWS cloud security controls, and treating the edge auth service as part of your serverless architecture with its own latency budget and alarms.

Frequently Asked Questions

Can CloudFront Functions call any external URL?

No. The destination must be an origin already configured on the same distribution. You pass a path and the origin ID, not a host name.

How many network calls can a function make?

One per invocation, counting both cf.fetch() and cf.beacon(). The limit is not adjustable.

How much do CloudFront Functions network calls cost?

$0.10 per million calls on top of function invocation charges, and included at no extra cost in the Pro flat-rate plan and above.

Should I still use Lambda@Edge?

If your logic needs more than one external call, larger payloads or more than 1 second, Lambda@Edge or origin-side logic is still the better fit. For quick, single lookups, CloudFront Functions network calls are now an option.

Need Help Designing Edge Logic on AWS?

Moving authentication, bot checks or personalisation to the edge changes how your security, latency and failure modes behave. If you would like an experienced team to review your CloudFront architecture, get in touch with Shanav and we can help you design a safe rollout.