This Lambda is broken by design. Please do not use it. We will improve this concept one day.
- Using AWS CloudFront as a CDN server.
- Docker and [email protected] for development.
If you don't need to modify the code you can use the prebuilt deploy packages provided as assets with each GitHub release.
They are built automatically using Travis CI *.
* Currently running tests on build is disabled because they do exact response body comparison which is different between Linux and MacOS.
Because our lambda requires native modules in npm packages e.g. for image optimization, compression etc. we need to rebuild entire node_modules on the same operating system that AWS Lambda is running on. Then the complete codebase is zipped into edge-lambda-deploy-package.zip archive which can be attached in Lambda Management Console.
To automatically generate edge-lambda-deploy-package.zip using docker image:
yarn create-packageOr enter the command directly:
docker run --rm --tty --volume "$(pwd):/var/app" mageops/aws-lambda-build:nodejs10.x nodejs-yarn edge-lambda-deploy-packageNOTE: Even though lambda's runtime should be based on Amazon Linux 2 which has libjpeg-turbo
included by default, this library seems to be missing. The custom build hook installs appropriate
so files into the lib/ subdirectory. It's possible that Lambda@Edge still uses
Amazon Linux 1 as the system runtime, what is not surprising given that this specific lambda
type does not support node12.x in contrast to "standard ones".
The package is built using mageops/aws-lambda-build. Check the corresponding GitHub repository for more information.
Go to Lambda Management Console and create new function (make sure you have US East (N. Virginia) region selected) with following data:
Name: originRequest
Runtime: Node.js 10.x
Role: Create new role from template(s)
Role name: Your desired name for a role.
Policy templates: Basic Edge Lambda permissions
Note: You can create your own role if you know what you are doing.
You will be redirected to function configuration, there you need to setup the following:
- Select
Upload a .ZIPfile inCode entry typefield. - Upload previously generated
edge-lambda-deploy-package.zip. - Make sure
Runtimeis set toNode.js 8.10. - Set
Handlerfield toorigin-request.handler.
- Set
Memory (MB)limit to1024MBfor best performance/cost ratio. - Set
Timeoutto about20s(compressing images larger then few MB takes a lot of time and can still be slower).
- Save all the changes.
- Release new version using
Actionsdropdown. - You will be redirected to certain version configuration.
- In
Designertab selectCloudFrontinAdd triggerssection. - Scroll down to
Configure Triggerssection. - Select your target CloudFront distribution in the
Distributionfield. - Leave cache behaviour at
*. - Set CloudFront event to
Origin Request. - Check
Enable trigger and replicate. - Confirm by clicking the
Addbutton. - Hit
Savebutton at the top-right. - Wait for CloudFront to apply the changes(usually a minute or two).