Create resize image Lambda function

  1. Open AWS Lambda console, then click Create function button LambdaConsole

  2. Enter function name, such as: resize-image

    • Choose Node.js 16.x for Runtime
    • Click Create function button CreateFunction
  3. Download source code file to your device

  4. function.zip (8382 ko)
  5. Click Upload from button

    • Choose .zip file CreateFunction
  6. Click Upload button

    • Then select the downloaded source code file
    • Click Save CreateFunction CreateFunction
  7. Next, add environment variables to adjust the width and height of the image

    • Click Configuration tab
    • Click Environment variables on the left menu
    • Click Edit CreateFunction
  8. Click Add environment variable, then add the following environment variables:

    • WIDTH: enter the new width of the photo, such as 200px.
    • HEIGHT: enter the new hight of the photo, such as 280px.
    • DES_BUCKET: S3 bucket name to store the changed image, such as: book-image-resize-stores.

Then, click Save CreateFunction

So we have completed the step of creating a Lambda function and configuring the environment variables for it. Next step, we will create an S3 bucket to store uploaded and edited images.