Lambda@Edge is a feature of Amazon CloudFront that lets you run code closer to users of your application, which improves performance and reduces latency. With Lambda@Edge, you don't have to provision or manage infrastructure in multiple locations around the world. You pay only for the compute time you consume - there is no charge when your code is not running.
With Lambda@Edge, you can enrich your web applications by making them globally distributed and improving their performance — all with zero server administration. Lambda@Edge runs your code in response to events generated by the Amazon CloudFront content delivery network (CDN). Just upload your code to AWS Lambda, which takes care of everything required to run and scale your code with high availability at an AWS location closest to your end user.
Benefits
How It Works
Use Cases
SIMPLIFY AND REDUCE ORIGIN INFRASTRUCTURE
You can use Lambda@Edge as an extension of or replacement for your origin. This enables you to do everything from simple HTTP request and response processing at the edge to more advanced functionality, such as website security, real-time image transformation, intelligent bot mitigation, search engine optimization, and more.
Website Security and Privacy
You can trigger a Lambda function to add HTTP security headers on all origin responses without having to modify your application code on your origin. This helps improve security and privacy for your users and content providers, while using CloudFront to deliver the content at low latencies.
Dynamic Web Application at the Edge
By combining Lambda@Edge with other AWS services, developers can build powerful web applications at the edge that automatically scale up and down—with zero origin infrastructure and administrative effort required for automatic scaling, backups, or data center redundancy.
Search Engine Optimization (SEO)
You can use Lambda@Edge to improve search engine optimization (SEO) for your website. For example, you can trigger a Lambda function to deliver a pre-rendered HTML page stored in Amazon S3 when the user-agent is a search engine bot such as Googlebot or Bingbot.
Intelligently Route Across Origins and Data Centers
By using Lambda@Edge to dynamically route requests to different origins based on different viewer characteristics, you can balance the load on your origins, while improving the performance for your users. For example, you can route requests to origins within a home region, based on a viewer's location.
Bot Mitigation at the Edge
Lambda@Edge can help you block unwanted bots at the edge, and let the authorized traffic go through. By intelligently mitigating these automated processes, you can help protect your origin infrastructure from unhelpful web crawlers and bots, while improving performance for real users.
IMPROVED USER EXPERIENCE
Lambda@Edge can help improve your users' experience with your websites and web applications across the world, by letting you personalize content for them without sacrificing performance.
Real-time Image Transformation
You can customize your users' experience by transforming images on the fly based on the user characteristics. For example, you can resize images based on the viewer's device type—mobile, desktop, or tablet. You can also cache the transformed images at CloudFront Edge locations to further improve performance when delivering images.
A/B Testing
You can test and serve different versions of your website to the users without re-directs or changing the browser URL. This allows you to seamlessly release updates to your website to improve your website's overall experience while continuing to deliver responsiveness for users.
User Authentication and Authorization
You can use Lambda@Edge to help authenticate and authorize users for the premium pay-wall content on your website, filtering out unauthorized requests before they reach your origin infrastructure. For example, you can trigger a Lambda function to authorize each viewer request by calling authentication and user management service such as Amazon Cognito.
User Prioritization
Lambda@Edge can help you to control and prioritize access to your website by routing users to different pages and experiences. For example, you can trigger a Lambda function that runs code to prioritize premium and paid users on your e-commerce website as the traffic surges during shopping sales. You can also redirect other shoppers to a temporary “waiting room”— an alternate site with branding and marketing deals where they can wait for a turn to access your main retail site.
User Tracking and Analytics
By using Lambda@Edge and Kinesis together, you can process real-time streaming data so that you can track and analyze globally-distributed user activity on your website and mobile applications, including click stream analysis.
Related content
Engage with other developers about Amazon CloudFront and Lambda@Edge in the discussion forum.