Setting up Lambda for image resizing
To use Sharp for Node.js properly, we need to compile it on a Linux server. To do so:
- Create a Node.js AWS Lightsail instance ($3.5 tier will do the job)
- Unzip imageresizer-main.zip, remove the node_modules folder, zip it and upload to Lightsail instance
- Run npm install inside folder directory
- Rezip all folder contents and upload to AWS Lambda
- When setting the environment variables configuration for the Lambda function, make sure CDN_URL includes the https:// at the front to avoid the code returning an incorrect header URL
Create an IAM user, e.g. resize-lambda-user, with S3 PutObject and GetObject permissions (S3 Object Lambda is not needed). Use this user's access key and secret key as environment variables for the Lambda function.