Enhancing redirect strategies with AWS CloudFront Functions and KeyValueStore

29/01/2024
Posted in Serverless
29/01/2024 Patrick Daulie

Elevating Your E-Commerce Experience with AWS

More and more, e-commerce businesses turn to serverless and cost-efficient hosting solutions from AWS, often combining CloudFront with S3, alongside other AWS services and third party APIs.

Let’s take a real-life example: a common challenge encountered in e-commerce is the graceful conclusion of a ‘flash sales’ event on a predefined date and time. Ensuring a seamless transition as these sales come to an end, is essential for maintaining customer satisfaction and fostering long-term loyalty.

In this case you want to avoid website redeployments or server-side changes. You could make use of a simple URL redirect ‘toggle switch’.
Enter AWS’s power at the edge : AWS CloudFront Functions and CloudFront KeyValueStore!

This blog post will explore how I used this simple, yet powerful (and new!) KeyValueStore feature to redirect users after sales end, without server-side headaches or code changes.

Creating a Seamless User Experience with CloudFront Functions :

CloudFront Functions brings computation to the edge, closer to the user, which results in lightning-fast execution. By attaching a function to my CloudFront distribution and linking it to a KeyValueStore, I could easily manage the flash sales states with minimal effort. The function checks a value in the KeyValueStore and if it’s “off,” users are redirected to a “Sale Ended” page.

As you can see in the screenshot of the Cloudfront Functions code, it is pretty straightforward to request the value of a key and then use it in your function logic.

Cloudfront KeyValueStore Function

Now you can use the value of the “Sales” KeyValue in your function logic.
This example performs a redirect when the Flash Sales has ended :

Cloudfront Redirect Function

You can probably discover other use cases or solutions built upon this feature, such as A/B testing, feature flags or access authorization based on data stored in the KeyValueStore.

Stay tuned for more posts, where I’ll dive deeper into the benefits of AWS serverless technologies, helping you tap into the potential of the cloud for your e-commerce and other application needs!

Do not underestimate the power of AWS Cloudfront Functions: it has supersonic execution times for your Viewer requests and Viewer Responses. Think about cache-key and header manipulation, access authorization at the Edge. And as mentioned, nifty URL rewrite and redirect capabilities.

In one of my upcoming blog posts, I will be adding more functionalities to Cloudfront/S3 web applications. So don’t miss out on the insights – follow our blog and join me on this journey to unlock the full potential of serverless architectures with AWS!

Conclusion:

CloudFront Functions and KeyValueStore simplify redirection after flash sales, showcasing the potency of edge computing.

  • SHARE
,

LET'S WORK
TOGETHER

Need a hand? Or a high five?
Feel free to visit our offices and come say hi
… or just drop us a message

We are ready when you are

Cloudar NV – Operations

Veldkant 7
2550 Kontich (Antwerp)
Belgium

info @ cloudar.be

+32 3 450 67 18

Cloudar NV – HQ

Veldkant 33A
2550 Kontich (Antwerp)
Belgium

VAT BE0564 763 890

    This contact form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    contact
    • SHARE