Skip to main content
POST
https://searchcompany-main.up.railway.app
/
api
/
domain
/
update-lambda-edge
Update Lambda@Edge
curl --request POST \
  --url https://searchcompany-main.up.railway.app/api/domain/update-lambda-edge
Update the Lambda@Edge function with new bot patterns and propagate to all CloudFront distributions.

When to Use

Call this endpoint when you’ve updated the bot detection patterns in lambda_code.js and want to deploy the changes to all customer domains. Common reasons to update:
  • New AI bot released (e.g., new Anthropic crawler)
  • Bot User-Agent pattern changed
  • Bug fix in routing logic

What This Does

  1. Uploads new Lambda code from lambda_code.js
  2. Publishes a new Lambda version (e.g., :1 → :2)
  3. Updates all CloudFront distributions to use the new version (parallel batches)

Timing

StepDuration
Lambda upload~5 seconds
Version publish~5 seconds
Distribution updates~1 minute per 100 distributions
Total for 1,000 distributions~15 minutes

Customer Impact

Zero downtime. CloudFront updates are rolling:
  • Old Lambda version continues handling requests
  • Traffic gradually shifts to new version
  • No interruption to customer websites

Authentication

This endpoint requires an internal API key. Include the X-API-Key header:
X-API-Key: your-internal-api-key

Example Request

curl -X POST https://searchcompany-main.up.railway.app/api/domain/update-lambda-edge \
  -H "X-API-Key: your-internal-api-key"

Example Response

{
  "status": "success",
  "lambda_arn": "arn:aws:lambda:us-east-1:577004485557:function:HostHeaderProxy:5",
  "distributions": {
    "total": 150,
    "successful": 150,
    "failed": 0,
    "failed_details": null
  }
}

Response Fields

FieldTypeDescription
statusstringsuccess or error
lambda_arnstringNew Lambda version ARN
distributions.totalnumberTotal distributions to update
distributions.successfulnumberSuccessfully updated
distributions.failednumberFailed to update
distributions.failed_detailsarrayDetails of any failures

Workflow

Step 1: Update Bot Patterns

Edit Backend/src/app/domain/setup_proxy/step_0_lambda_setup/lambda_code.js:
const BOT_PATTERNS = [
  // Existing bots...
  "gptbot",
  "claudebot",
  "perplexitybot",
  
  // Add new bot here
  "newaibot",
  "another-crawler",
];

Step 2: Deploy Changes

curl -X POST https://api.searchcompany.ai/api/domain/update-lambda-edge \
  -H "X-API-Key: your-internal-api-key"

Step 3: Verify

The response shows how many distributions were updated. All customer domains will now detect the new bot patterns.

Rate Limiting

The endpoint processes distributions in batches of 10 with a 1-second delay between batches to respect AWS CloudFront API limits.

Error Handling

If some distributions fail to update:
  • Successfully updated distributions use the new Lambda
  • Failed distributions continue using the old Lambda (still works)
  • Retry the endpoint to attempt failed distributions again

Example Response with Failures

{
  "status": "success",
  "lambda_arn": "arn:aws:lambda:us-east-1:577004485557:function:HostHeaderProxy:5",
  "distributions": {
    "total": 150,
    "successful": 148,
    "failed": 2,
    "failed_details": [
      {
        "distribution_id": "E1ABC123",
        "status": "error",
        "error": "Distribution is currently being updated"
      },
      {
        "distribution_id": "E2DEF456",
        "status": "error",
        "error": "Access denied"
      }
    ]
  }
}

Security

This endpoint requires an internal API key and should only be used by admins. It modifies infrastructure that affects all customer domains.