Posted On: May 3, 2021
Amazon CloudFront announces the general availability of CloudFront Functions, a new serverless edge compute capability. You can use this new CloudFront feature to run JavaScript functions across 225+ CloudFront edge locations in 90 cities across 47 countries. CloudFront Functions is built for lightweight HTTP(S) transformations and manipulations, allowing you to deliver richer, more personalized content with low latency to your customers.
CloudFront Functions is ideal for lightweight CloudFront CDN customizations that can run on every request to enable high scale and latency sensitive operations like HTTP header manipulations, URL rewrites/redirects, and cache key normalizations. For example, you can use CloudFront Functions to rewrite requests to language specific versions of your site based on the Accept-Language header of the incoming request. You can also use CloudFront Functions to validate custom tokens to authorize incoming requests. Because these functions run at all of CloudFront’s edge locations, they can scale instantly to millions of requests per second with minimal latency overhead.
CloudFront Functions is natively built-in to CloudFront, allowing you to easily build, test, and deploy viewer request and viewer response functions entirely within CloudFront. Our GitHub repo makes it easy for you to get started by offering a code collection that you can use as a starting point for building functions. You can build functions in the CloudFront console using the IDE, or from the CloudFront APIs/CLI. After you write your code, you can test your function against a CloudFront distribution, to ensure it will run properly after it’s deployed. The test functionality in the console offers a visual editor to quickly create test events without needing to edit JSON.
You can use CloudFront Functions in addition to the existing AWS Lambda@Edge capability that also allows you to run custom code in response to CloudFront events. You should continue using Lambda@Edge for computationally intensive origin request and response operations like server side rendering or image optimizations. CloudFront Functions is priced at $0.1 per million invocations. For more information about pricing, visit the CloudFront pricing page. To learn more about CloudFront Functions, refer to the CloudFront Functions Launch Blog, CloudFront Developer Guide, or feature FAQs.