Published on

Optimizing Web Applications at the Edge: CloudFront Functions and KeyValueStore

Authors
Tired of using AWS Console? 🤕
Time to boost your productivity with Cloudash — an AWS desktop client.

Amazon Web Services (AWS) has introduced two innovative solutions for enhancing web applications at the edge: CloudFront Functions and CloudFront KeyValueStore. These services integrate with Amazon CloudFront, AWS's content delivery network (CDN), to deliver data, videos, applications, and APIs to customers globally with low latency and high transfer speeds.

CloudFront Functions

CloudFront Functions is a serverless scripting platform that allows the execution of lightweight JavaScript code at CloudFront edge locations. This service is particularly suitable for simple HTTP(s) request/response manipulations that are executed by short-lived functions. It offers a flexible programming experience with performance, scale, and cost-effectiveness, making it possible to execute functions on every request.

Key Features

  • Lightweight Processing: Ideal for cache-key manipulations, URL rewrites, HTTP header manipulation, and access authorization.
  • New Isolation Model: Uses process-based isolation instead of virtual machine-based isolation, enabling functions to run for less than one millisecond, handling millions of requests per second without significant impact on CDN performance.
  • Integration with CloudFront: Can be triggered after CloudFront receives a viewer request and before CloudFront forwards the response to the viewer.
  • Comparison with Lambda@Edge: Supports JavaScript and can be executed in over 218 CloudFront Edge Locations, with a maximum execution time of less than 1 millisecond and maximum memory of 2MB.
  • Practical Usage: Functions can be created, tested, and published through the CloudFront console, with a lifecycle including building, testing, publishing, and associating with CloudFront distributions.

CloudFront KeyValueStore

CloudFront KeyValueStore is a secure, global, low-latency key-value datastore accessible from within CloudFront Functions. It enables advanced customizable logic at CloudFront edge locations, allowing for the separation of function code and associated data, thereby simplifying function code and making it easier to update data without deploying code changes.

Key Features

  • Independence of Data and Function Code: Allows for independent updates to function code and associated data, eliminating the need for redeployment for every small configuration change.
  • Use Cases: Ideal for URL rewrites/redirects, A/B testing, feature flags, and access authorization.
  • Supported Formats: Values in the key-value pairs can be stored as strings, byte-encoded strings, or in JSON format.
  • Security: Ensures encryption of key-value store data at rest and during transit, with decryption occurring in memory at CloudFront edge locations during function execution.

Practical Application

A practical example of using CloudFront Functions and KeyValueStore involves rewriting URLs using configuration data stored in KeyValueStore. This can be particularly helpful for managing multiple services as part of a website, like switching between different versions of a blog platform or other web services.

Availability and Pricing

Both CloudFront Functions and KeyValueStore are available in all edge locations globally. CloudFront Functions offer a free tier as part of the AWS Free Usage Tier, with pricing based on the number of invocations. For CloudFront KeyValueStore, pricing is based on read/write operations from the public API and read operations from within CloudFront Functions.

In conclusion, AWS CloudFront Functions and KeyValueStore present robust, flexible, and cost-effective solutions for developers seeking to enhance their web applications' performance and customization at the edge, leveraging the global reach and low latency of Amazon CloudFront.

Tired of switching between AWS console tabs? 😒

Cloudash provides clear access to CloudWatch logs and metrics, to help you make quicker decisions.
Try it for free:

Logs screen