Posted On: May 3, 2021
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.