How to use Amazon S3 Object Lambda to generate thumbnails

What do we want to do

The plan 🧭

  1. Create an S3 bucket and put there original images
  2. Set up an Access Point for the bucket we created
  3. Create an empty Lambda function
  4. Add Object Lambda Access Point to connect S3 bucket and Lambda function
  5. Create a script to retrieve an original image from S3 bucket and its thumbnail from the S3 Object Lambda
  6. Add code to Lambda function to resize an image
  7. Run the script created in step 5 to get two images or different sizes

Instructions 🛠️

Step1: S3 bucket

Step2: S3 Access Point

Step3: Lambda function

Step4: Object Lambda Access Point

Step 5: Script to download an original image and its thumbnail

npm init
npm install aws-sdk
The Lambda exited without successfully calling WriteGetObjectResponse

Step6: Add code in Lambda function

  • get original image from S3 bucket with the help of axios
  • use sharp to resize it (we’ll talk below how to add nodeJs packages)
  • use properties from event’s context to generate a new request
  • call writeGetObjectResponse and submit resized image
Initial code of lambda function, which won’t work

Challenge # 1 : writeGetObjectResponse is not defined

Challenge#2 : MethodNotAllowed

Lambda function with a workaround for 405 error

Challenge#3 : darwin-x64' binaries cannot be used on the ‘linux-x64’ platform

npm install --arch=x64 --platform=linux sharp

Step 7 : Run the script


More information and more examples



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Olena Kutsenko

Olena Kutsenko

Software engineer, who is passionate about agility and sustainable software development achieved through simplicity, technical excellence and good design.