AWS:: Lambda@edge & CloudFront Function
Last updated
Was this helpful?
Last updated
Was this helpful?
CloudFront Functions are a great way to expand your product's capabilities or completely overhaul the way it performs certain tasks by executing code at the CDN layer instead of on origin servers. By opting to use Functions, you'll be able to build a variety of solutions, such as the following:
Serve different content based on the device being used to make the request by rewriting the URL of the request based on the condition you care about. For example, you can send video content at different resolutions to users based on their devices.
Implement Geo-targeting to ensure the right content is served depending on the origin country of the end user. For example, you can use this to give Purchasing Power Parity (PPP) Discounts.
Inspect or modify any of the request headers before forwarding to the origin or client.
Protect the content on your web properties from being hot-linked by other websites.
Add security rules and filters to block unwanted visitors and bots.
Set up an A/B test by controlling what response is served based on cookies. This helps with testing different versions of a website without changing the URL or redirect.
Respond directly (and quickly) from the edge without hitting the origin.
Implement access control and authorization for the content delivered through CloudFront and redirect unauthenticated users to login pages.
Analyze and track user activity on your website and mobile applications.
Add HTTP security headers (such as a Content Security Policy) to all responses without modifying your application code - https://www.honeybadger.io/blog/aws-cloudfront-functions
CloudFront Functions
Lambda@Edge
Runtime support
JavaScript (ECMAScript 5.1 compliant)
Node.js, Python
Execution location
218+ CloudFront Edge Locations
13 CloudFront Regional Edge Caches
CloudFront triggers supported
Viewer request Viewer response
Viewer request Viewer response Origin request Origin response
Maximum execution time
Less than 1 millisecond
5 seconds (viewer triggers) 30 seconds (origin triggers)
Maximum memory
2MB
128MB (viewer triggers) 10GB (origin triggers)
Total package size
10 KB
1 MB (viewer triggers) 50 MB (origin triggers)
Network access
No
Yes
File system access
No
Yes
Access to the request body
No
Yes
Pricing
Free tier available; charged per request
No free tier; charged per request and function duration