Create resize image Lambda function

  1. Open AWS Lambda console

LambdaConsole

  1. Click Create function button

CreateFunction

  1. Enter function name, such as: resize-image
  • Choose Node.js 16.x for Runtime
  • Click Create function button

CreateFunction

  1. Download source code file to your device
  • function.zip (8382 KB)
    1. Click Upload from button
    • Choose .zip file

    UploadSource

    1. Click Upload button
    • Then select the downloaded source code file
    • Click Save

    UploadSource

    1. 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

    UploadSource

    1. 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, book-image-resize-store.

    Then, click Save

    UploadSource

    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.