KINTO Tech Blog
AWS

Exploring Edge Functions Available in CloudFront

Cover Image for Exploring Edge Functions Available in CloudFront

Introduction

Hello! This is Iki from the Cloud Infrastructure Team of the Platform Group (in the Osaka Tech Lab) at KINTO Technologies. I heard that a skilled young team member from Osaka will be writing about troubleshooting CloudFront Functions, so I’ll cover CloudFront edge functions as some foundational knowledge in advance!

Let's start with an overview of CloudFront

CloudFront is a content delivery network (CDN), designed to bring content closer to users by strategically placing CDN points worldwide and caching content at these locations. Users can enjoy low-latency access by connecting to the nearest CDN point. There are two types of edge locations: one closer to the user and a regional edge cache (regional edge location) situated closer to the origin server.

What is an Edge Function?

An edge function is a function that runs on an edge server, processing traffic at the location where it is received. By using edge functions, you can execute operations at the time of request or response, and in our company we mainly implement and operate the following functions:

  • Redirect the URL of the response
  • Add header
  • Resize the image according to the request parameters

When to Run an Edge Function

An edge function can be run at the following four times.

  • Viewer request
  • Viewer response
  • Origin request
  • Origin response


With CloudFront, the viewer manages all communication, so if there’s no cached content, the origin handles common processing. This setup is useful for controlling information sent to the origin, resizing cached data, and other optimizations.

Types of Edge Functions

There are two types of edge functions: CloudFront Function and Lambda@Edge.

CloudFront Function

An edge function that runs at an edge location close to the user.
It performs large-scale latency-sensitive CDN customizations. CloudFront Functions are ideal for simple tasks like header manipulation and redirection, and they cost less than one-sixth of Lambda@Edge.

Since it runs at the edge location closest to the user, it responds to viewer requests and responses, but not origin requests and responses.

Lambda@Edge

Edge functions that run in the region edge cache close to the origin. For processing tasks that CloudFront Functions cannot handle, you can use other AWS services, including the AWS SDK, and access file systems by leveraging Lambda@Edge or similar AWS services.

Lambda@Edge is an extension of AWS Lambda, and although it appears the same on the console, it has some functional limitations—such as not allowing user-defined environment variables. Please keep these restrictions in mind.

While the Lambda@Edge function itself is stored in the Virginia region, it operates by creating replicas in various edge locations, allowing it to run within each regional edge cache.
As a result, the concurrent Lambda execution limit and access limits for each service apply in the specific region where the function runs (such as the Tokyo region in Japan). Be mindful of these limits to ensure smooth operation.

It supports viewer requests, viewer responses, origin requests, and origin responses.


The Differences between CloudFront Function and Lambda@Edge

CloudFront Functions Lambda@Edge
Programming language JavaScript Node.js / Python
Event source Viewer request
Viewer response
Viewer request
Viewer response
Origin request
Origin response
Scale Number of requests: More than 10,000,000 per second Number of requests: Up to 10,000 per second per region
The duration of the function Less than 1ms Viewer: 5 seconds
Origin: 30 seconds
Maximum memory 2 MB 128–3,008 MB
Maximum size of the function code and included libraries 10KB Viewer: 1MB
Origin: 5MB
Network access No Yes
Access to file systems No Yes
Access to the request body No Yes
Access to location and device data Yes Viewer request: No
Viewer response: Yes
Origin request: Yes
Origin response: Yes

Quote: CloudFront Functions and Lambda@Edge selection

Usage of Edge Functions in KINTO Technologies

KINTO Technologies, though not yet fully utilizing it, recommends CloudFront Functions. They can help manage costs and reduce concurrent Lambda executions for viewer requests and responses, especially in high-traffic environments.

Besides, CloudFront Functions have more limitations compared to Lambda@Edge. Therefore, we prioritize reducing development and operational costs by using Lambda@Edge, rather than focusing solely on minimizing daily AWS expenses.

Conclusion

In this post, I discussed CloudFront edge functions (CloudFront Function and Lambda@Edge). By understanding and leveraging edge functions, you can enhance your system’s capabilities and improve the user experience. However, given their strict limitations, any mistakes can result in errors and unexpected outcomes. I hope this article has provided valuable insights and will be beneficial for your development work.

Stay tuned for an upcoming post on troubleshooting CloudFront Function!

We're also seeking new team members to join us at the Platform Group (Osaka Tech Lab), so don't hesitate to reach out!

KINTO Technologies Corporation Platform G Recruitment Top 
wantedly

Facebook

関連記事 | Related Posts

We are hiring!

【クラウドエンジニア】Cloud Infrastructure G/東京・大阪

KINTO Tech BlogWantedlyストーリーCloud InfrastructureグループについてAWSを主としたクラウドインフラの設計、構築、運用を主に担当しています。

【フロントエンドエンジニア リーダークラス(DX等)】DX開発G/東京・大阪

DX開発グループについてモビリティにかかわる様々なDXサービス・プロダクトの企画推進とシステム開発・クリエイティブ制作を行っています。 販売店DX ターゲティング&パーソナライズ オウンドメディア 募集背景当グループでは、全国約3,600店舗のトヨタ販売店の営業プロセスを中心に、販売店スタッフのお困りごとをテクノロジーとクリエイティブの力で解決に導く「販売店DX事業」を展開しています。