Ends in
00
days
00
hrs
00
mins
00
secs
ENROLL NOW

Get $4 OFF in AWS Solutions Architect & Data Engineer Associate Practice Exams for $10.99 each ONLY!

Cloudfront Function URL Demo

Last updated on October 3, 2023

In this article, we will guide you through the process of setting up a CloudFront Function for your CloudFront distribution. We’ll walk you through a scenario where we use CloudFront Functions to redirect users to different content based on their device type. By the end of this guide, you’ll gain a clear understanding of how CloudFront Functions can benefit your specific use case.

Creating an S3  Bucket

This bucket will simply serve as a mock origin for the CloudFront distribution that we’ll be creating. If you have some test buckets lying around, you may use them instead and skip this step. 

  1. Navigate to the Amazon S3 service in the AWS Management Console.
  2. Click on Create bucket.
  3. Provide a unique name for your bucket.
  4. Choose a region.
  5. Tutorials dojo strip
  6. Click on ‘Create’.

Creating the CloudFront Function

  1. On the left-hand side of the CloudFront Console, click Functions.
  2. Click Create Function.
  3. Name your function, then click Create Function.
  4. On the IDE, copy and paste the code found on this Github link.
  5. Select the Publish tab, then click Publish Function.

Creating an Origin Request Policy

  1. On the left-hand side of the CloudFront Console, click Policies.
  2. Select Origin request.
  3. Under Custom Policies, click Create origin request policy.
  4. Enter CloudFront-Is_Headers for the name.
  5. In the Origin request settings, select All viewer headers and the following CloudFront header, then add the following headers:
    • CloudFront-Is-Desktop-Viewer
    • CloudFront-Is-Mobile-Viewer
  6. Finally, click Create.

Creating a CloudFront Distribution

  1. On the left-hand side of the CloudFront Console, click Distributions, then click on the Create Distribution button.
  2. In the Origin settings section, for Origin Domain Name, select the S3 bucket you created earlier from the drop-down list.
  3. Leave the rest of the settings in this section as default.
  4. Scroll down to the Default Cache Behavior Settings. For Cache Policy, select CachingOptimized from the drop-down list.
  5. For Origin Request Policy, select the custom policy you created earlier from the drop-down list.
  6. Scroll down to the Functions Association. Click on Add function.
  7. In the function type dropdown, select CloudFront Functions.
  8. In the function ARN/Name, choose the CloudFront function you created earlier.
  9. Finally, click Create Distribution.

 

Verification

Now comes the fun part, verifying our function. Once your CloudFront distribution is up and running, copy its distribution URL and access it using your browser. If you access the URL through a desktop, you should be taken to a GIF showing a person at a desk. On the other hand, if you access the URL on a mobile device, you should be taken to a GIF representing a mobile phone. Congratulations! You’ve successfully set up and tested an Amazon CloudFront Function for device-based content personalization.

Get $4 OFF in AWS Solutions Architect & Data Engineer Associate Practice Exams for $10.99 ONLY!

Tutorials Dojo portal

Be Inspired and Mentored with Cloud Career Journeys!

Tutorials Dojo portal

Enroll Now – Our Azure Certification Exam Reviewers

azure reviewers tutorials dojo

Enroll Now – Our Google Cloud Certification Exam Reviewers

Tutorials Dojo Exam Study Guide eBooks

tutorials dojo study guide eBook

FREE AWS Exam Readiness Digital Courses

Subscribe to our YouTube Channel

Tutorials Dojo YouTube Channel

FREE Intro to Cloud Computing for Beginners

FREE AWS, Azure, GCP Practice Test Samplers

Recent Posts

Written by: Carlo Acebedo

Carlo is a cloud engineer and a content creator at Tutorials Dojo. He's also a member of the AWS Community builder and holds 5 AWS Certifications. Carlo specializes in building and automating solutions in the Amazon Web Services Cloud.

AWS, Azure, and GCP Certifications are consistently among the top-paying IT certifications in the world, considering that most companies have now shifted to the cloud. Earn over $150,000 per year with an AWS, Azure, or GCP certification!

Follow us on LinkedIn, YouTube, Facebook, or join our Slack study group. More importantly, answer as many practice exams as you can to help increase your chances of passing your certification exams on your first try!

View Our AWS, Azure, and GCP Exam Reviewers Check out our FREE courses

Our Community

~98%
passing rate
Around 95-98% of our students pass the AWS Certification exams after training with our courses.
200k+
students
Over 200k enrollees choose Tutorials Dojo in preparing for their AWS Certification exams.
~4.8
ratings
Our courses are highly rated by our enrollees from all over the world.

What our students say about us?