- AWS Lambda@Edge (enabled Preview)
- One Amazon CloudFront Distribution (origin doesn't matter)
- IAM role (basic execution is enough)
- npm to install Node.js dependencies
The Lambda@Edge will be invoked whenever a new "Viewer Request" event is triggered by CloudFront.
The Lambda Function will behave as follows:
- If the requested resource is NOT available locally (i.e. not an HTML file), the request can proceed to the origin
- If the local template exists, it will be read and rendered using Plates with a few dynamic variables (i.e. "title" and "today)
- The resulting HTML is then minified and eventually compressed, based on the request HTTP headers (response headers are correctly set as well)
- The final HTTP body is directly returned to the client without hitting the CloudFront origin
cd this-gist
npm install
zip -r ../edge-deployment-package.zip ./*
- The deployment package cannot exceed 1MB, and a manual hack was required to include the 'html-minifier' library (i.e. reducing its size from 3MB to 500KB)
It looks like you have to compress the response yourself, if you are generating a dynamic reponse on 'Viewer Request'.
You can find out more at the HTTP Response with Compressed Static Content section here.