38
loading...
This website collects cookies to deliver better user experience
Feature | CloudFront Functions | Lambda@Edge |
---|---|---|
Runtime | JavaScript (ECMAScript 5.1 compliant) |
Node.js, Python |
CloudFront triggers | Viewer request Viewer response | Viewer request Viewer response Origin request Origin response |
Execution time | 1 millisecond | 5 seconds (viewer triggers) 30 seconds (origin triggers) |
Memory | 2MB | 128MB (viewer triggers) 10GB (origin triggers) |
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 |
CloudFrontFunction:
Type: AWS::CloudFront::Function
Properties:
Name: UpdatePath
AutoPublish: true
FunctionCode: !Sub |
function handler(event) {
var request = event.request;
var uri = request.uri;
uri = uri.replace(/\/$/, '\/index.html');
request.uri = uri;
return request;
}
FunctionConfig:
Comment: !Sub Append index.html to folder paths
Runtime: cloudfront-js-1.0
aws cloudfront test-function \
--name ExampleFunction \
--if-match ETVABCEXAMPLE \
--event-object fileb://event-object.json
--stage DEVELOPMENT
{
"version": "1.0",
"context": {
"eventType": "viewer-request"
},
"viewer": {
"ip": "1.2.3.4"
},
"request": {
"method": "GET",
"uri": "/mytest/",
"headers": {
"host": {"value": "example.org"}
}
}
}
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
....
FunctionAssociations:
- EventType: viewer-request
FunctionARN: !GetAtt CloudFrontFunction.FunctionMetadata.FunctionARN
#LambdaFunctionAssociations:
# - EventType: viewer-request
# LambdaFunctionARN: !Ref LambdaARN
38