Back to results for “Lambda & Serverless”
AWS › Amazon CloudFront & Content Delivery

How do Lambda at Edge and CloudFront Functions extend the capabilities of a CloudFront distribution?

Advanced

Answer

Lambda at Edge lets you run more complex custom code, written in Node.js or Python, at CloudFront edge locations to modify requests and responses, such as personalizing content or performing authentication checks, while CloudFront Functions offer a lighter weight, faster, and cheaper option written in JavaScript for simpler tasks like URL rewrites or header manipulation, both running much closer to the user than your origin server.
function handler(event) {
    var request = event.request;
    request.uri = request.uri.replace('/old-path/', '/new-path/');
    return request;
}
Real-world example A media company uses a CloudFront Function to automatically redirect users requesting an outdated URL structure to the correct new page, without ever needing to involve the origin server in that decision.

Common follow-ups: When should you use Lambda at Edge instead of CloudFront Functions?;What are the execution time limits for each option?