Recently, AWS announced the general availability of CloudFront Functions, a new edge computing capability. With this new CloudFront feature, customers can run JavaScript functions across the Cloud Front edge locations worldwide.
AWS customers use Amazon CloudFront as a service to deliver content such as data, videos, and APIs securely at high speed and low latency in a developer-friendly environment. Since July 2017, they could leverage the Lambda@Edge feature suitable for complex, compute-heavy operations executed in a regional edge cache. And now, the company expands the service with CloudFront Functions – a scripting platform that allows customers to run lightweight JavaScript code at edge locations.
AWS Lambda@Edge functionality is run from regional data centers and not from the edge locations since more computing power is available in these regional data centers – yet this slows down the delivery speed. Additionally, this solution cannot deliver custom content or code unique to each edge location, as AWS CloudFront Functions can through the JavaScript code.
The content is delivered to AWS data centers from the nearest edge location of the global network. When customers request content or code through AWS CloudFront, the request is routed to that edge location that offers the fastest speed and lowest latency - providing the end-users the content or code at the fastest speed possible.
Source: https://aws.amazon.com/blogs/aws/introducing-cloudfront-functions-run-your-code-at-the-edge-with-low-latency-at-any-scale/
According to the AWS News blog post by Danilo Poccia, Chief Evangelist (EMEA) at Amazon Web Service, CloudFront Functions are ideal for lightweight processing of web requests, such as:
- Cache-key manipulations and normalization: Transform HTTP request attributes (such as URL, headers, cookies, and query strings) to construct the cache-key, which is the unique identifier for objects in cache and is used to determine whether an object is already cached.
- URL rewrites and redirects: Generate a response to redirect requests to a different URL.
- HTTP header manipulation: View, add, modify, or delete any of the request/response headers.
- Access authorization: Implement access control and authorization for the content delivered through CloudFront by creating and validating user-generated tokens, such as HMAC tokens or JSON web tokens (JWT), to allow/deny requests.
In addition, he stated:
To give you the performance and scale that modern applications require, CloudFront Functions uses a new process-based isolation model instead of virtual machine (VM)-based isolation used by AWS Lambda Lambda@Edge. We had to enforce some restrictions, such as avoiding network and file system access. Also, functions run for less than one millisecond. In this way, they can handle millions of requests per second while giving you great performance on every function execution. Functions add almost no perceptible impact to overall content delivery network (CDN) performance.
CloudFront Functions are similar to Cloudflare Workers, a serverless execution environment that runs across all of the company's edge infrastructure. A respondent on a Reddit thread wrote:
Cloudflare, since its beginnings, has had a strong lightweight native scripting capability in lua. I'm hoping that this AWS offering is something similar to that, exposing some underlying CloudFront capabilities that we can use at a much lower cost than lambda@edge and with a minimal performance impact.
Also, Arnaud Bezançon, CTO at Advantys, stated in a tweet:
Cloudflare Edge ecosystem is impressive as well with Workers, KV, and Durable objects.
AWS CloudFront Functions is a great addition for AWS users! The Edge is definitely a new field of innovation and a playground for new frameworks! (edge-side)
AWS CloudFront Functions is natively built into AWS CloudFront - through the AWS Management Console, AWS Command Line Interface (CLI), AWS SDKs, and AWS CloudFormation; users can leverage CloudFront Functions.
The company currently prices CloudFront Functions $0.1 per million invocations. More details on pricing are available on the pricing page. Furthermore, developers can find guidance through the documentation and Developer Guide.