us-east-1, at those edge locations.
This integration evaluates inbound request bodies before CloudFront forwards
them to an AI endpoint you operate. It does not inspect model responses,
individual tool calls inside an agent, or employee access to third-party AI
services.
Integration capabilities
Before you start
Start with the policy in Observe mode. Findings appear in Activity without
affecting traffic. Switch to Enforce after reviewing the results. See
Policies.
1. Create a collector API key
On the CloudFront collector, open Auth and create a key. It is shown once.2. Write the request handler
The function decodes the exposed body, callsPOST /v1/evaluate with the collector key as a
bearer token, and returns either a 403 response or the original request:
status short-circuits the request: CloudFront
answers the viewer and your origin is never called. Returning request
forwards it. The allow, report, ask, and transform verdicts reach the
origin. An ask verdict is recorded and allowed because the edge cannot prompt
a user.
The key is inline above for readability only. Step 3
replaces it.
3. Configure the collector key
Lambda@Edge does not support environment variables, soprocess.env is not an
option. There are two ways to supply the collector key:
Either way the key never travels in the request body.
4. Publish the function and deploy it as Lambda@Edge
Author the Node.js function in us-east-1 and publish a numbered version; Lambda@Edge associates a version, never$LATEST. CloudFront then replicates
that version to its edge locations. Allow several minutes for changes to
propagate.
5. Choose a request trigger and enable Include Body
Attach the function to either the Viewer request or Origin request event of the cache behavior that carries your AI paths, and enable Include Body. Include Body exposes the payload. Without it,request.body is not
populated, the handler’s request.body?.data guard is false, and requests are
forwarded without evaluation or an error. CloudFront supports this option on
both request events.
CloudFront first selects the matching cache behavior. The trigger then
determines when the function runs and how much of the body it can inspect:
Use viewer request when you need to evaluate cache hits. Use origin request when
you need the higher body limit and do not need to evaluate cache hits.
Scope the association to the behavior that serves AI routes. A
default-behavior association also applies to unrelated assets in the
distribution.
6. Account for request-body truncation
CloudFront exposes up to 40 KB of the body to a viewer-request function and up to 1 MB to an origin-request function. When a body exceeds the applicable limit, CloudFront setsrequest.body.inputTruncated to true and provides only
the prefix within that limit.
7. Verify
- Put the policy in Enforce and POST a prompt that trips a rule to a path on the guarded behavior.
- Confirm that the caller receives
403 Forbiddenwith the bodyBlocked by TrustGuard. - Confirm the event in TrustGuard Activity, under the
consumer_idtaken fromx-user-id.
Reference
Coverage
The function evaluates input bodies up to the selected trigger’s limit: 40 KB
on viewer request or 1 MB on origin request. It returns 413 when CloudFront
marks a body as truncated. It does not inspect responses, expose individual
tool calls, or support redaction. Each evaluated request adds one round trip
from the edge to
{TRUSTGUARD_URL}.
What is evaluated
Every call is
POST /v1/evaluate with the collector
key as a bearer token, and the policy’s
detectors decide the verdict. Verdicts are
request-level: a block stops the whole request, never one field of it. The
handler sends direction: input only, so Output-phase rules on the policy never
evaluate, however many of them you write.
Configuration
Configure the integration across CloudFront, Lambda, and the handler body:
The sample does not define failure behavior. Without
try/catch, an
unreachable or slow TrustGuard call throws and CloudFront returns an error. Wrap
the call and choose explicitly: return request to fail open, or return your
own 403 to fail closed.
Attributes
consumer_id: read from thex-user-idrequest header, empty string when absent. It is what per-consumer policy routing keys on, so without it every caller shares the collector’s default policy.session_id: read from thex-session-idrequest header. The sample sends""when the header is absent. Send a stable, verified conversation ID if you need reliable grouping in Activity.- The function reads the header values present at the selected trigger. CloudFront does not derive either value for you. If your front end does not send those headers, map them from another source, such as a session cookie or a claim your edge authentication already validates. For an origin-request trigger, ensure that your cache or origin request policy preserves the identity headers.
Troubleshooting
Related
- Evaluate API: request and response contract for the endpoint the function calls
- Policies: Observe and Enforce modes, including gate configuration
- Collectors: collector keys and policy resolution
- Other edge collectors: Cloudflare · Fastly · Akamai
- Lambda@Edge trigger events: when viewer-request and origin-request functions run
- Lambda@Edge request-body restrictions: Include Body limits for each request event