What is Lambda@Edge and what are its use cases?
Answer
Lambda@Edge is an extension of AWS Lambda that lets you run functions at CloudFront edge locations (200+ locations worldwide) in response to CloudFront events, closer to end users. It intercepts four types of CloudFront events: viewer request (before checking cache), origin request (on cache miss, before forwarding to origin), origin response (after origin response, before caching), viewer response (before sending to client). Use cases: (1) A/B testing — redirect percentage of traffic to different URLs at edge; (2) URL rewrites/redirects — rewrite URLs based on device type, geolocation, or query params; (3) Authentication at edge — validate JWT tokens at edge before hitting origin; (4) Security headers — add CSP, HSTS headers to all responses; (5) Dynamic content — personalize cached pages based on cookies; (6) Image transformation — resize/convert images at edge. Limitations: 5-second timeout, 128MB memory (much more restrictive than standard Lambda). CloudFront Functions is a lighter alternative for simple URL manipulations.
Previous
How do you implement authentication in a serverless API?
Next
How do you implement a CRON job with serverless functions?
More Serverless Architecture Questions
View all →- Intermediate How do you reduce cold start latency in serverless functions?
- Intermediate What is AWS Step Functions and when would you use it?
- Intermediate How do you handle state in serverless applications?
- Intermediate What is the Serverless Framework and how does it work?
- Intermediate How do you implement authentication in a serverless API?