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

แชร์
ฝัง
  • เผยแพร่เมื่อ 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/OneLightWebDev/ima...
    Sharp NPM: www.npmjs.com/package/sharp
    Guide: docs.aws.amazon.com/lambda/la...
    Github: github.com/nikitapryymak
    Support Me: www.paypal.com/paypalme/nikit...
    Contact Me: onelightwebdev@gmail.com
    #nodejs #aws #javascript
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 41

  • @cheey3839
    @cheey3839 8 หลายเดือนก่อน +2

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

  • @brunolaranjeira3855
    @brunolaranjeira3855 7 หลายเดือนก่อน

    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.

  • @ricksegalCanada
    @ricksegalCanada หลายเดือนก่อน

    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.

  • @hmvarshney5222
    @hmvarshney5222 หลายเดือนก่อน

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

  • @vjself
    @vjself 4 หลายเดือนก่อน

    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 3 หลายเดือนก่อน

      @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 17 วันที่ผ่านมา

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

  • @aleksey6151
    @aleksey6151 9 หลายเดือนก่อน +3

    goated tutorial

  • @vvyael
    @vvyael 4 หลายเดือนก่อน

    Amazing

  • @Matt6176
    @Matt6176 4 หลายเดือนก่อน

    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  4 หลายเดือนก่อน

      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.

  • @WriteCodeWithMaan
    @WriteCodeWithMaan หลายเดือนก่อน

    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?

  • @hashimali4262
    @hashimali4262 6 หลายเดือนก่อน

    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  4 หลายเดือนก่อน

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

  • @sammunroe389
    @sammunroe389 4 หลายเดือนก่อน +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 4 หลายเดือนก่อน +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  4 หลายเดือนก่อน

      thanks for sharing!

  • @tomscall3811
    @tomscall3811 8 หลายเดือนก่อน

    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  4 หลายเดือนก่อน

      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 4 หลายเดือนก่อน +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

  • @regilearn2138
    @regilearn2138 9 หลายเดือนก่อน

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

    • @nikita-dev
      @nikita-dev  8 หลายเดือนก่อน

      I made a similar video to this already: th-cam.com/video/vVBqEYNXxy8/w-d-xo.html

  • @ChadDiaz-qk4fb
    @ChadDiaz-qk4fb 2 หลายเดือนก่อน

    @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  2 หลายเดือนก่อน

      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.

  • @sahebdhara1286
    @sahebdhara1286 4 หลายเดือนก่อน +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 3 หลายเดือนก่อน +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 3 หลายเดือนก่อน

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

  • @vikramadityasinghai5968
    @vikramadityasinghai5968 7 หลายเดือนก่อน

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

    • @nikita-dev
      @nikita-dev  4 หลายเดือนก่อน

      Pillow is a popular python library for this

  • @harshal_joshi
    @harshal_joshi หลายเดือนก่อน

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

    • @harshal_joshi
      @harshal_joshi หลายเดือนก่อน

      Please reply me

  • @quanne131
    @quanne131 5 หลายเดือนก่อน

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

  • @anirudh5101
    @anirudh5101 3 หลายเดือนก่อน

    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 2 หลายเดือนก่อน +1

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

    • @anirudh5101
      @anirudh5101 2 หลายเดือนก่อน

      @@Benjamin-Chavez Thanks Benjamin 😄

  • @Kimitri
    @Kimitri 7 หลายเดือนก่อน

    why use 2 separate buckets?

    • @nikita-dev
      @nikita-dev  7 หลายเดือนก่อน +1

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

    • @Kimitri
      @Kimitri 7 หลายเดือนก่อน

      That makes sense. Thank you for replying to me.

    • @Kimitri
      @Kimitri 7 หลายเดือนก่อน

      ​@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 8 หลายเดือนก่อน

    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 7 หลายเดือนก่อน

      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.