> ## Documentation Index
> Fetch the complete documentation index at: https://docs.searchcompany.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Technical overview of the Update Lambda@Edge endpoint

# POST /api/domain/update-lambda-edge

Updates the Lambda\@Edge function and propagates changes to all CloudFront distributions.

## Purpose

This endpoint:

1. Reads the current `lambda_code.js` file (with updated bot patterns)
2. Uploads it to AWS Lambda and publishes a new version
3. Updates ALL CloudFront distributions to use the new version

## Architecture

```mermaid theme={null}
flowchart TD
    A[Request] --> B[Read lambda_code.js]
    B --> C[Upload to AWS Lambda]
    C --> D[Publish New Version]
    D --> E[Get All Distributions]
    E --> F[Update Each Distribution]
    F --> G[Return Results]
```

## Use Cases

* Update bot detection patterns
* Fix Lambda\@Edge bugs
* Deploy new routing logic
* Update AI crawler handling

## Internal Services

### update\_lambda\_edge

Handles the Lambda update and CloudFront propagation.

**Location:** `src/app/apis/domain/update_lambda_edge/handler.py`

### generate\_lambda\_code

Generates the Lambda\@Edge code with current bot patterns.

**Location:** `src/app/apis/domain/update_lambda_edge/generate_lambda_code.py`

## Lambda\@Edge Function

The Lambda\@Edge function runs at CloudFront edge locations and:

* Detects AI bot user agents
* Routes AI bots to the AI-optimized site
* Routes regular users to the origin

## Propagation Time

CloudFront distribution updates typically take 5-15 minutes to propagate globally.

## Response Fields

| Field                   | Type    | Description                     |
| ----------------------- | ------- | ------------------------------- |
| `status`                | string  | "success" or error              |
| `lambda_version`        | string  | New Lambda version number       |
| `distributions_updated` | integer | Number of distributions updated |

## Code Location

```
src/app/apis/domain/update_lambda_edge/routes.py
```
