Upload files to S3 using API Gateway - Step by Step Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ก.ค. 2024
  • In this video, I show how to upload files using API Gateway and S3 integration. In the first part of the video, I explain the required IAM role and policy to run the demo. After that, I create the API Gateway with the S3 bucket as the backend service. I'll show how to map the path params from the API Gateway to the S3 bucket and object key.
    00:00 Introduction
    01:20 Solution Architecture
    03:13 IAM Role and Policy Creation
    05:30 Create API Gateway
    09:33 Deploy the API
    If you want to learn more about AWS Services, make sure to
    subscribe to the channel:
    TH-cam 🎥 - / @enricoportolan
    Medium: / enrico-portolan
    🌎 Find me here:
    Twitter - / enricop89
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @jonty0001
    @jonty0001 2 ปีที่แล้ว +1

    This is a great video on API gateway integration with S3. Enrico, thanks so much for sharing this knowledge with the community.

  • @purplishjen
    @purplishjen ปีที่แล้ว +1

    Clear and straight to the point. Good job!

  • @jonathanvargasv2009
    @jonathanvargasv2009 2 ปีที่แล้ว +1

    Practical, helpful, and precise. Thanks for all your help.

  • @Leonquenix
    @Leonquenix 2 ปีที่แล้ว +1

    You are a lifesaver! This saved me so much time. Thank you so much!

  • @markcheng7254
    @markcheng7254 2 ปีที่แล้ว +1

    Worked perfectly. Amazing stuff!!

  • @yuming123
    @yuming123 2 ปีที่แล้ว +1

    Great video and just cover enough details for me to pick up in 10 mins, cheers !!

  • @sandeeppanchal8615
    @sandeeppanchal8615 2 ปีที่แล้ว +8

    Clean, clear and straight explanation. It solved my problem in 10 minutes. Good start with your video.

  • @nicktran8595
    @nicktran8595 2 ปีที่แล้ว

    Thank you so much. I just got stucked with AWS doc. You saved me :)

  • @glassin1093
    @glassin1093 2 ปีที่แล้ว +1

    Great thanks for this video - exactly what I needed

  • @paul-macfarlane
    @paul-macfarlane ปีที่แล้ว +2

    Very helpful, thanks! I initially setup API Gateway with a Lambda Integration because I didn't know this was possible, but I definitely agree this is the preferred approach since with Lambda you have to deal with cold starts and managing code.

  • @inversebrah
    @inversebrah 2 ปีที่แล้ว

    great tutorial, thank you Enrico!

  • @principe.borodin
    @principe.borodin 10 หลายเดือนก่อน

    WOW, it works fantasticly!!!

  • @arpankhetani7818
    @arpankhetani7818 2 ปีที่แล้ว +1

    Thank you for your explanation.. Very well explained and you kept it same..

  • @karikalanramakrishnan9286
    @karikalanramakrishnan9286 2 ปีที่แล้ว +1

    Excellent guidelines, able to successfully upload png and csv file too. Thanks.

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

    Thank you for this. You’ve saved me a lot of time

  • @theautomationchannel6920
    @theautomationchannel6920 2 ปีที่แล้ว

    Thanks ..Really great effort..happy to find you channel

  • @ahack210
    @ahack210 2 ปีที่แล้ว

    Very useful video, thanks!

  • @manojreddy152
    @manojreddy152 ปีที่แล้ว

    Awesome Job!! Well executed!!

  • @RBusch_
    @RBusch_ ปีที่แล้ว

    Thank you for this tutorial (from Brazil)

  • @undertaker9138
    @undertaker9138 2 ปีที่แล้ว

    Very helpful, thanks.

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

    legend! very helpful thanks a lot!

  • @ezequielsanchezventurini2184
    @ezequielsanchezventurini2184 2 ปีที่แล้ว

    Thanks, this is really useful

  • @Bemidbar
    @Bemidbar 2 ปีที่แล้ว

    Super! Thank you!

  • @Ritunjan
    @Ritunjan 2 ปีที่แล้ว

    Great thanks it is awesome!!

  • @KyleMerl
    @KyleMerl ปีที่แล้ว +5

    For anyone getting an "internal server error", I had to enable cloudwatch logs in order to debug, and discovered I had a typo in my "path override". You can enable cloudwatch logs by going to "stages", select your stage, click the Logs/Tracing tab, and then enable cloudwatch logs. Keep in mind I think cloudwatch logs do incur costs, so turn them off when you're finished.

  • @greendsnow
    @greendsnow ปีที่แล้ว

    AWS is absolutely ridiculous. I couldn't do it without you.
    I can't believe how people are put through learning this stuff.
    I'm actually very angry with the lack of intuition here.

    • @greendsnow
      @greendsnow ปีที่แล้ว +1

      now every file uploads but none of them opens...

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

    save my day, Thanks

  • @tsielomudau1849
    @tsielomudau1849 2 ปีที่แล้ว

    it worked for me thanks

  • @nevilholmes5900
    @nevilholmes5900 ปีที่แล้ว

    thank you so much

  • @federicovdemartino4915
    @federicovdemartino4915 2 ปีที่แล้ว +1

    Man, you cannot imagine how you saved my live here!

  • @nil.hunter
    @nil.hunter 11 หลายเดือนก่อน +2

    I don't understand why do I need to use PUT instead of POST to upload a file in a folder in S3. Could someone to break it down, please?

  • @zhongtom2625
    @zhongtom2625 ปีที่แล้ว +1

    Thanks for the video Enrico. Is there a way to get the file url in the api's response? That will be the complete use case of the api. Thanks.

  • @user-sb8nb5id6c
    @user-sb8nb5id6c 9 หลายเดือนก่อน

    Hi,
    Thank you for this demo. Just one question, I want to use the same pattern to send XML structure in memory not stored in a file system to be be then stored as object into S3. Is this working directly using API Gateway or do I need a lambda to manage S3.putObject(buffer)?

  • @hebahijjawe3489
    @hebahijjawe3489 2 ปีที่แล้ว

    Thank you, i have a question ... can i send file ACL list in Simple Storage Service (S3) PUT ? because i need the file public read access

  • @lifeessense4283
    @lifeessense4283 2 ปีที่แล้ว

    I had similar requirement but additionally I have to save the path and few additional parameters in db, will the first approach works? Can you explain that as well how to configure.

  • @ramyahello
    @ramyahello ปีที่แล้ว

    Very useful video !!! Thanks a lot. Should we add authentication is it really necessary in this case ? Since u r already using iam role

  • @yonatantre
    @yonatantre ปีที่แล้ว

    Hey thank you for the solution. Can you provide serveless yml solution as well for same issue?

  • @gregbanister
    @gregbanister 2 ปีที่แล้ว +1

    Would it be possible to create a single SAM template that will generate all of the resources and permissions. If so, an example would be great.

  • @niranjangadekar3897
    @niranjangadekar3897 ปีที่แล้ว +1

    Hi Enrico, This is very helpful can you do the same using cloudformation?

  • @joaoluismoraes7215
    @joaoluismoraes7215 ปีที่แล้ว

    Is it possible to get a custom response? Once I upload the image, can I get the file URL or something like that?

  • @harishkp8631
    @harishkp8631 ปีที่แล้ว

    hey, quick question, instead of postman, how can we upload the picture through a frontend code that is in a s3 bucket and this s3 bucket is connected to the same api gateway

  • @nick_jacob
    @nick_jacob ปีที่แล้ว

    Do you have a way to add meta data with the image?

  • @anilpoudel5974
    @anilpoudel5974 2 ปีที่แล้ว

    Sir suppose I have AL3 file in my desktop and I need to convert that format and read using third party API how I will upload file in that API and retrieve that file in particular format without the use of any object just normally passing desktop file.

  • @Sony-il2ti
    @Sony-il2ti 2 ปีที่แล้ว +1

    please can you explain and clarify a bit what an API resource is and how it is different from a method? thank you

  • @munozhoracio
    @munozhoracio 2 ปีที่แล้ว +3

    help,
    MethodNotAllowed
    The specified method is not allowed against this resource.
    PUT
    SERVICE
    .....
    ....+...+...=

  • @stevebuonincontri6853
    @stevebuonincontri6853 ปีที่แล้ว

    Thank u This is just what I needed. It turns out my videos are too large for lambda. So it is now going directly to S3. So is it true that lambda has a 6mb max for video processing? My files were even smaller having issues ~5.1mb??
    Then I realize there is no way to control how large a user's video upload will be and needed to go directly to S3. Maybe I should have gone directly to transcribe.??????

  • @geetanshawriteme
    @geetanshawriteme ปีที่แล้ว +2

    Can we upload the file with POST method instead of PUT?

  • @sport-jz8dd
    @sport-jz8dd 2 ปีที่แล้ว

    Hi, Thank you for the Clean, clear, and straight explanation. can you please let me know how to create folders and place images in them using this API.

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      if you specify a folder path in the API, such as images/website/myphoto.jpg, it should create the relative path. I haven't tested but it should work

  • @kushmishra
    @kushmishra ปีที่แล้ว

    hey , im getting a method not allow error when im calling PUT call to the api through the postman please HELP !

  • @sumit84ky
    @sumit84ky 2 ปีที่แล้ว

    First of all, Thank you so much for such a wonderful video explaining the problem use case with solution.
    I have one request, how do we secure the API gateway with basic AUTH or AWS Signature (preferred) ?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      I think this guide can help you: docs.aws.amazon.com/apigateway/api-reference/signing-requests/

  • @allofmystuffs
    @allofmystuffs 2 ปีที่แล้ว +1

    We didn't limit the file size to 4MB. How to do that.?

  • @TheRealKosalaHandlersMail
    @TheRealKosalaHandlersMail 19 ชั่วโมงที่ผ่านมา

    Can this be done using Terraform only?

  • @lollo4ever
    @lollo4ever 2 ปีที่แล้ว +1

    Great video! It does work on Postman, but what about CORS? What about calling that API from a front-end? Thank you

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +2

      Hi Alessandro, sure. If you are deploying your app with Serverless Framework the easiest way to enable CORS is the following:www.serverless.com/blog/cors-api-gateway-survival-guide/. Otherwise for a more general guide you can follow: docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      Let me know if it helps, otherwise feel free to ask :)

  • @muralikrish9515
    @muralikrish9515 ปีที่แล้ว

    By using api url, can i upload log files from an application

  • @lucasvargasquintana8396
    @lucasvargasquintana8396 ปีที่แล้ว

    Great video! Thanks! I have one question about it:
    On Postman, I'm getting this error: IllegalLocationConstraintException
    Message: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to
    Can you give me a hand on it?

  • @sidduk5389
    @sidduk5389 2 ปีที่แล้ว

    Great video, what are the solutions fot multiple images and over 10 MB size?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      The best approach is to use multipart upload docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html

  • @jasontwinters
    @jasontwinters 2 ปีที่แล้ว

    Great tutorial!
    In my case the bucket name will always be the same. How can I eliminate the bucket name from the URL?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      You can set a custom dns record with route 53

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

    Configuring bucket is working fine. I want to put the file into specific nested folder in the bucket. Anyone tried this?

  • @user-py1xm2zz6g
    @user-py1xm2zz6g 2 ปีที่แล้ว +3

    After uploading the image, it shows me a white small box in the browser. I also added "*/*" in the binary media types section.

    • @javascript_developer
      @javascript_developer ปีที่แล้ว

      You might need to re-deploy the api again in order to work.

  • @divineer627
    @divineer627 2 ปีที่แล้ว

    This was very helpful. Is it possible to have a video on uploading files larger than 100MB in S3?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      Yes it is using multipart upload docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html

  • @ArjunKumar-df6pr
    @ArjunKumar-df6pr ปีที่แล้ว

    How to give the filename same as what we are uploading from postman

  • @prashantsingh9645
    @prashantsingh9645 2 ปีที่แล้ว

    It's is showing internal server Error ! tell me what is the problem, or what am i doing wrong for some reason

  • @raviullagaddi2089
    @raviullagaddi2089 2 ปีที่แล้ว +2

    Thank you so much. and one question
    How to return s3 file location with this api?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +2

      I think you can add it on the Response mapping - Body

    • @raviullagaddi2089
      @raviullagaddi2089 2 ปีที่แล้ว +1

      @@EnricoPortolan : Getting this error : {
      "message": "Unsupported Media Type"
      }
      What is the content type need to pass in header?
      i have added this --> image/jpeg in binary media type

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

    Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.request.path.bucket]. I got this error for adding url path parameters. Can you help me out

  • @harishstealth9112
    @harishstealth9112 2 ปีที่แล้ว

    How we can Mutiple files Upload ? Any Idea .

  • @deepshikhagarg5661
    @deepshikhagarg5661 ปีที่แล้ว

    This was really helpful. Also how can i connect it with my html code. I want to upload image in s3 using UI..

    • @javascript_developer
      @javascript_developer ปีที่แล้ว

      You can use this url as a restful api url and use html form file upload and call the api on submit

  • @jiongnanliu5541
    @jiongnanliu5541 2 ปีที่แล้ว

    some follow up questions, I followed your approach and successfully uploaded object to S3 bucket, but is there way to add metadata value at upload time? I added the x-amz-meta-* key in the headers according to the docs, but failed. Do you know why? Thanks!

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      have you tried following this guide: aws.amazon.com/premiumsupport/knowledge-center/custom-headers-api-gateway-lambda/ ?

    • @jiongnanliu5541
      @jiongnanliu5541 2 ปีที่แล้ว +1

      @@EnricoPortolan Thanks! Is there anyway that I don't need to use lambda, directly putting x-amz-meta-* in request headers sent to API gateway, which directly put object and metadata in S3.

    • @sebascardonac
      @sebascardonac 2 ปีที่แล้ว

      @@jiongnanliu5541 I try to do someting similar but I don’t how configurate the apigw to add header to send tags to the bucket.

  • @uttamtarsariya8492
    @uttamtarsariya8492 2 ปีที่แล้ว

    Can Have first approach?

  • @lifeankit
    @lifeankit 2 ปีที่แล้ว

    Can you please upload a video with the first architecture? I dont know how to read the uploaded file in lamda. Thank you. Great content. :)

  • @tumirantao3677
    @tumirantao3677 2 ปีที่แล้ว

    I am receiving missing authentication token error. Was your bucket public in the example?

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      it wasn't, authentication error could be you are specifying the wrong URL address

    • @gurpreetkaur-cw8wo
      @gurpreetkaur-cw8wo หลายเดือนก่อน

      same error how you resolve it

  • @moeyk97
    @moeyk97 2 ปีที่แล้ว

    What if I want to store an RFID Tag Number and then connect the S3 bucket to Elastic Beanstalk? (where my website is located) pls if you have any idea how this can be done let me know I would really really appreciate it, and it would help me greatly with my project.

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      What do you mean by connecting S3 to beanstalk? Can you elaborate please?

    • @moeyk97
      @moeyk97 2 ปีที่แล้ว

      @@EnricoPortolan I developed a website using html/php/css/javascript and I want my website to interact with the items that I upload to S3, I uploaded the code of the website to Elastic Beanstalk and successfully connected it to a RDS too

    • @moeyk97
      @moeyk97 2 ปีที่แล้ว

      and when my website can fetch the items from S3 bucket, I want it to behave accordingly to what I have in the RDS, e.g. if what it has read is available on the RDS then it would return the item. I hope that makes sense.

  • @riazahmad5975
    @riazahmad5975 ปีที่แล้ว

    Hello Sir ! please make a vidoe how to upload csv data to dynamodb using nodejs in serverless framework

  • @mjr8771
    @mjr8771 ปีที่แล้ว

    mine is saying missing authentication token

  • @calm2584
    @calm2584 2 ปีที่แล้ว

    How to fetch these files

  • @user-mt2ud3ir8y
    @user-mt2ud3ir8y 2 ปีที่แล้ว

    while successfully uploading the image to S3, I cannot open these images after downloading them from S3.......

    • @user-py1xm2zz6g
      @user-py1xm2zz6g 2 ปีที่แล้ว

      Have you found the way how to fix this?

  • @nithintm1748
    @nithintm1748 2 ปีที่แล้ว

    How to do it with lambda

  • @tnmyk_
    @tnmyk_ 2 ปีที่แล้ว

    I got an error on Postman saying "Missing Authentication Token". Can you please help

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว

      That error usually means you are using the wrong endpoint/url. Make sure you have spelled the url correctly or configured the parameters on the api gateway

    • @sumit84ky
      @sumit84ky 2 ปีที่แล้ว +1

      I was mistakenly using the "POST" method and hitting the same error. I guess, you are using POST method too in postman, we need to use PUT. Hope this helps.

  • @MySnezana
    @MySnezana 2 ปีที่แล้ว

    I am receiving Internal server error, any idea? Thank you

    • @bhoomikajs6989
      @bhoomikajs6989 2 ปีที่แล้ว

      hey..i have recieved the same error...did u resolve your error?

  • @cqh7851
    @cqh7851 2 ปีที่แล้ว +1

    Did i do something wrong? The image file uploaded just shows a white box.

    • @EnricoPortolan
      @EnricoPortolan  2 ปีที่แล้ว +1

      did you add the file extension?

    • @cqh7851
      @cqh7851 2 ปีที่แล้ว

      @@EnricoPortolan yea in the path parameters and in the binary media types section.

    • @user-py1xm2zz6g
      @user-py1xm2zz6g 2 ปีที่แล้ว

      @Enrico Portolan the same problem, white box when downloading from s3

    • @user-py1xm2zz6g
      @user-py1xm2zz6g 2 ปีที่แล้ว

      Have you found the way how to fix this?

    • @javascript_developer
      @javascript_developer ปีที่แล้ว

      @@user-py1xm2zz6g Inside setting add binary media types add "*/*" and re-deploy api.

  • @jiongnanliu5541
    @jiongnanliu5541 2 ปีที่แล้ว +1

    wish I just watched your video earlier...

  • @chienlingliu
    @chienlingliu 2 ปีที่แล้ว

    thank you but you spoke really fast