Resize Images with Node.js and AWS Lambda (and S3)

Поделиться
HTML-код
  • Опубликовано: 25 сен 2023
  • In this video you'll learn how to create, modify, deploy, and test an AWS Lambda. I will show you how to set permissions through IAM roles/policies, and also how to set up S3 triggers to invoke your Lambda when an image is uploaded to a bucket. We will use the Sharp NPM package to easily resize images, and the AWS S3 SDK to interact with our buckets.
    Code: github.com/nikitadev-yt/image...
    Sharp NPM: www.npmjs.com/package/sharp
    Guide: docs.aws.amazon.com/lambda/la...
    Github: github.com/nikitapryymak
    Support Me: www.buymeacoffee.com/nikitadev
    Contact Me: nikitadev292@gmail.com
    #nodejs #aws #javascript
  • НаукаНаука

Комментарии • 43

  • @ricksegalCanada
    @ricksegalCanada 2 месяца назад

    Thanks for taking the time to do this video. Your explanation style is excellent as all too often youtubers forget we don't know and they forget to explain things properly. Well done.

  • @cheey3839
    @cheey3839 10 месяцев назад +2

    Thank u!!! Yours is the most up to date tutorial, with details.

  • @brunolaranjeira3855
    @brunolaranjeira3855 8 месяцев назад

    Amazing work my friend. Your code worked like a charm. Only thing I changed was to hardcode the destination Bucket instead of using ENV variables. Thank you from Brazil.

  • @hmvarshney5222
    @hmvarshney5222 2 месяца назад

    Great course! Simple and to-the-point, unlike others.

  • @gianfrancoperaltabravo6004
    @gianfrancoperaltabravo6004 25 дней назад

    Amazing video !

  • @vjself
    @vjself 5 месяцев назад

    I couldn't actually get this to work following your video (sharp really does have some issues running in lambda) but cloning your repo and adjusting the code to my needs did the trick. Thank you so much for this it was incredibly helpful!

    • @DeveloperDsb
      @DeveloperDsb 4 месяца назад

      @vjself did you created your own function.zip file? if yes, could you please tell me how u did this because I tried to do so by running the command npm run package but I am getting the error "PS C:\Users\Dell\Desktop\Lambda_function\image-resizer-lambda> npm run package
      > thumbnail-generator-lambda@1.0.0 package
      > zip -r function.zip .
      'zip' is not recognized as an internal or external command,
      operable program or batch file."

    • @R.Yuvashri
      @R.Yuvashri Месяц назад

      Did you found the solution... Im still stucked in it

  • @aleksey6151
    @aleksey6151 10 месяцев назад +3

    goated tutorial

  • @vvyael
    @vvyael 5 месяцев назад

    Amazing

  • @WriteCodeWithMaan
    @WriteCodeWithMaan 2 месяца назад

    How can we access the sharp library without adding any dependency or without adding any layer to lambda? How your lambda function is reading the sharp library?

  • @lucasfranzolin
    @lucasfranzolin 27 дней назад

    do you know why exactly I keep getting "sharp module not found"? I'm even zipping the node_modules

  • @hashimali4262
    @hashimali4262 7 месяцев назад

    Great work.
    Ok I have a question when we upload image from frontend via post request it get stored in s2 and lambda function get triggered and image converted and stored to another s3 bucket.
    Now I want to send the converted image back as response to the user how I may able to do it?
    as my flask python coed will not wait for the completing of conversion in lambda

    • @nikita-dev
      @nikita-dev  5 месяцев назад

      you would probably need to implement polling (on the bucket that stores resized images).

  • @Matt6176
    @Matt6176 5 месяцев назад

    Hello and thank you for this tutorial! Could you please explain what the purpose of the package-lock.josn file is? Will the function run without it? Thank you!

    • @nikita-dev
      @nikita-dev  5 месяцев назад

      The package-lock file just stores the versions of all of the dependencies in your package json at the point of installation. I would not recommend removing this file.

  • @ChadDiaz-qk4fb
    @ChadDiaz-qk4fb 3 месяца назад

    @nikita-dev - I'd like to set something like this up but will take an original image and output a web image, mobile image and thumbnail image. Can you assist how to do this?

    • @nikita-dev
      @nikita-dev  3 месяца назад

      After you fetch the original image in S3, you need to run the Sharp resize function 3 times, passing in your desired widths for web, mobile & thumbnail. Then you’ll need to save off those 3 images in your output bucket, with their sizes included in the key.

  • @sammunroe389
    @sammunroe389 5 месяцев назад +2

    Great tutorial. I am running into one snag. Whenever I extract the function zip, modify index.js to 400px instead of 200px, re-zip, and upload....it tells me it can't find module 'index'

    • @sammunroe389
      @sammunroe389 5 месяцев назад +2

      Figured it out! Don't zip the functions parent folder. Select all files and zip, to a new zipped folder. Very strange but it fixed it.

    • @nikita-dev
      @nikita-dev  5 месяцев назад

      thanks for sharing!

  • @sahebdhara1286
    @sahebdhara1286 5 месяцев назад +2

    The deployment package of your Lambda function "lamda-for-image-resize" is too large to enable inline code editing. However, you can still invoke your function.

    • @alexander_ci
      @alexander_ci 4 месяца назад +1

      One way around this is using a Lambda layer and pointing your dependencies to that Layer, then that normally makes it a much smaller package.

    • @vigneshtamizh4091
      @vigneshtamizh4091 4 месяца назад +1

      Store the zip file in S3 bucket and provide the S3 object url in lambda upload

  • @tomscall3811
    @tomscall3811 9 месяцев назад

    So that's it with the Lambda code :). I have the feeling that I have to rewrite my whole app just to make it run on Lambda. Or is there an easy way? I use multer-sharp-s3 in my app, where everything is stored in an S3 bucket. Everything works great locally. But there are problems on Lambda. How can I get it to run. What additional code do I need for Lambda?

    • @nikita-dev
      @nikita-dev  5 месяцев назад

      It might be a permissions error (make sure the lambda has access to the right buckets). Also check the lambda logs for specific errors

    • @tomscall3811
      @tomscall3811 5 месяцев назад +1

      @@nikita-dev Thank you very much. I didn't understand the function of Lambda back then. I wanted to publish an entire app, which led to problems. I then switched to Elastic Beanstalk

  • @harshal_joshi
    @harshal_joshi 2 месяца назад

    9:02
    i have a error like zip' is not recognized as an internal or external command

  • @regilearn2138
    @regilearn2138 10 месяцев назад

    can u show us how to save/upload image/multiple image in s3 bucket with lambda function in react app,

    • @nikita-dev
      @nikita-dev  9 месяцев назад

      I made a similar video to this already: ruclips.net/video/vVBqEYNXxy8/видео.html

  • @vikramadityasinghai5968
    @vikramadityasinghai5968 9 месяцев назад

    If i was to do this using python, which library could i use ???????/

    • @nikita-dev
      @nikita-dev  5 месяцев назад

      Pillow is a popular python library for this

  • @anirudh5101
    @anirudh5101 4 месяца назад

    Can anyone tell me is this project worth putting In my resume. Im just a beginner and pursuing my masters right now

    • @Benjamin-Chavez
      @Benjamin-Chavez 3 месяца назад +1

      maybe as part of a larger project, but not necessarily by itself. (just my opinion)

    • @anirudh5101
      @anirudh5101 3 месяца назад

      @@Benjamin-Chavez Thanks Benjamin 😄

  • @quanne131
    @quanne131 6 месяцев назад

    can you make i video about deploy nodejs app to aws free

  • @Kimitri
    @Kimitri 8 месяцев назад

    why use 2 separate buckets?

    • @nikita-dev
      @nikita-dev  8 месяцев назад +1

      mainly to avoid any chance of recursive invocations. if you go to 11:33 I talk a little bit about that.

    • @Kimitri
      @Kimitri 8 месяцев назад

      That makes sense. Thank you for replying to me.

    • @Kimitri
      @Kimitri 8 месяцев назад

      ​@nikita-dev I have another question, my application is for an photo studio, and the employees gonna upload more than 1000 photos for each album. The select all the photos and click in upload, I need to do some configuration on lambda function to works with it with no problems?

  • @user-ov3iz5wv5v
    @user-ov3iz5wv5v 9 месяцев назад

    Hi!
    When i test the event i got error as
    Response
    {
    "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module 'index'
    Require stack:
    - /var/runtime/index.mjs",
    "trace": [
    "Runtime.ImportModuleError: Error: Cannot find module 'index'",
    "Require stack:",
    "- /var/runtime/index.mjs",
    " at _loadUserApp (file:///var/runtime/index.mjs:1087:17)",
    " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)",
    " at async start (file:///var/runtime/index.mjs:1282:23)",
    " at async file:///var/runtime/index.mjs:1288:1"
    ]
    }

    • @rassdsign8788
      @rassdsign8788 8 месяцев назад

      Hi the reason you got that error is because you zip the folder instead you should directly zip the file so that when you open zip file it directly can read index.js.