Setting up Lambda for image resizing
Compiling sharp for x86_64 architecture
To use Sharp for Node.js properly, we need to compile it on an x86_64 Linux server. Create a Node.js AWS Lightsail instance ($3.5 tier will do the job), then run the following:
mkdir sharpfolder
cd sharpfolder
npm i sharp
zip -r sharp.zip node_modules/
You can now download this zip via WinSCP, and upload it as a Lambda layer.
Lambda function configuration
Environment Variables
When setting the environment variables for the Lambda function, make sure CDN_URL includes the https:// at the front to avoid the code returning an incorrect header URL.
Execution Role
If you don't already have an IAM user for invoking the function, and an IAM role to serve as the execution role, you will need to create both of these for the function to work properly. See this article for how to do that: Implementing an image resizing solution yourself.