Creating an API with Serverless - API Gateway and AWS Lambda

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2019
  • Full Serverless playlist here • The Serverless Framewo...
    In this lesson we'll learn how we can build a Lambda function that works with API Gateway to create an API.
    I this video you'll learn:
    - How to set up a Lambda in Serverless
    - What response you need to return to work with API Gateway
    - How to deploy the Lambda and API Gateway using Serverless
    - How to test GET requests in the browser
    Starting Code: github.com/SamWSoftware/Serve...
    Final Code: github.com/SamWSoftware/Serve...
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @johnbarker5686
    @johnbarker5686 3 ปีที่แล้ว +10

    Great tutorial- thank you so much!
    Updating this to latest:
    provider:
    ...
    httpApi:
    cors: true
    functions:
    getUser:
    handler: lambdas/getUser.handler
    events:
    - httpApi:
    method: GET
    path: /get-user/{ID}

    • @Unnonamus
      @Unnonamus 3 ปีที่แล้ว

      You saved me from going off the rails, thank you! This should probably be stickied at the top.

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      Yes, there's a v2 of serverless now which has made the inclusion of httpApi. You should still be able to use "http" though

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      @@rayandwayne3275 Glad that you found it useful

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

    Great simple and clear.. that is what I was looking for, tutorials that go straight to the point .. thank you

  • @stefan1632
    @stefan1632 3 ปีที่แล้ว

    Great training videos series! I'm currently studying for developer associate and this is helping cement the concepts.

  • @AmruAshik
    @AmruAshik 3 ปีที่แล้ว

    the bestttt video series ever for js developers!! thank you!

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

    Great tutorial - thank you so much

  • @WezPyke
    @WezPyke 4 ปีที่แล้ว

    Thanks Sam for the great video.

  • @muzammalabdulghafoor6418
    @muzammalabdulghafoor6418 3 ปีที่แล้ว

    Wow man! Thats really helpful, I really appreciate your effort what you're putting...Thanks a lot!

  • @MarcelaoVMS
    @MarcelaoVMS 3 ปีที่แล้ว

    Thank you very much for this amazing video!

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

    Thx for good video again!

  • @letsgodevs
    @letsgodevs 3 ปีที่แล้ว

    Thank you thank you thank you very much sir for this video

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      Thanks for commenting on all my videos :) It really helps share them to more people

  • @asekawarnakulasooriya7909
    @asekawarnakulasooriya7909 3 ปีที่แล้ว

    great video!

  • @victorps5366
    @victorps5366 3 ปีที่แล้ว

    All... Excelent!!

  • @iotforlife6691
    @iotforlife6691 3 ปีที่แล้ว

    Starting to watch

  • @user-nm5kd8pm8z
    @user-nm5kd8pm8z ปีที่แล้ว +1

    Thank you for the video. It didn't show me a link to check this function. Where can I find my link?

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

    Great video

  • @muzammalabdulghafoor6418
    @muzammalabdulghafoor6418 3 ปีที่แล้ว

    Keep it up!

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

    These are amazing tutorials. You should consider opening a course on Udemy. You are way better than those AWS Udemy instructors.

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

      I've done one small course on Udemy but I'm considering doing a TH-cam SaaS build series and then adding extra details and putting it on Udemy too.

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

    Thank you so much for this guide. I did everything the way you teach but I have a problem because when I go into endpoint I have an error {"message": "Internal server error"} - How to fix this ??

    • @CompleteCoding
      @CompleteCoding  4 ปีที่แล้ว

      This means there's a bug in the code. You can run
      sls logs -f ${yourFunctionName}
      to get the latest logs. You should then be able to see what the error is from them. The other option is to go into the console, find your lambda, select "monitoring" and then "View logs in CloudWatch" which will show you the logs in the console.

  • @josejaimes4965
    @josejaimes4965 4 ปีที่แล้ว

    Hi Sam,
    I noticed I had to comment all the lines inside DemoBucketUpload when I tried to run "sls deploy" command because of this error :
    An error occurred: NewResource - mynewbucketwithserveless-1927 already exists.
    After that, it works!
    ( You can see this section in this video at 10:36 )

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

      That just means that someone has already claimed that bucket name. It might even have been you in a previous project.
      You could have also just altered the bucket name to achieve the same result

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

    Hi, Excellent tutorial. I need help to identify the problem why I'm getting a 502 in the browser when I try to run the API. serverless deploy worked fine. Thank you.

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

    Awesome video!
    I was wonder, do you prefer working with js or typescript?

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

      I definitely prefer typescript now. It took a bit to get used to but makes everything more consistent now.
      I can define what I expect to receive from an api request and then everything will autocomplete. It warns me when I pass an incorrect parameter or have a typo.

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

    Great video, do you know an example of applying idempotency to the api to avoid repeated requests?

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

      You could write a 'lock' to a dynamo table on the first request so later requests know not to process.
      Idempotency is usually only be required for update requests where the data is relative to the current value. Eg. Increment likes by one.
      I try to avoid this kind of request where ever possible, instead providing the actual values.
      I avoid it because there are almost always race conditions or other effects that can cause issues.

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

      @@CompleteCoding ok thanks a lot for explaining

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

    This is fantastic. But is the a specific reason why you chose to use Require.JS rather than ES6 modules? Anyway, thanks and keep 'em coming.

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

      The first few videos in this series were done before the use of webpack. If you try and use ES6 and import without webpack then your lambdas will always error. I probably should have updated them all in the webpack video.

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

    hello, this is a great tutorial by the way!!! I have two quick questions which I wish you could demonstrate in the video as well, was
    1. How do you invoke the message, {message: "missing the ID from the path"} and
    2. how do you access 'event' which you console logged from the editor?
    Thanks!!!

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

      You can't trigger that message via the api. If you don't pass an id then api gateway won't pass the message to the lambda. Its likely to happen if you point the wrong endpoint to the wrong lambda.
      To see the logs, open the lambda in the console. Then click the 'monitoring' tab and 'view in cloudwatch'. You can see everything that gets console.log out in your code.

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

      @@CompleteCoding Thank you!!! Best tutorial

  • @rohith_sivapuram4804
    @rohith_sivapuram4804 3 ปีที่แล้ว

    Heloo
    Wt was extension needed for serverless. Yml file?

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      You don't need any vs code extensions to use serverless.yml files

  • @AhmedBesbes
    @AhmedBesbes 4 ปีที่แล้ว

    Excellent video !
    Could you make video on how building a deployment package using serverless and python?

    • @CompleteCoding
      @CompleteCoding  4 ปีที่แล้ว

      I've not done much with Python in production but the process is the same.
      create a new project with "sls create --template aws-python --path myService"
      setup your AWS credentials if you haven't already
      modify the python endpoint or create more of your own
      update the serverless.yml file for your changes or new endpoints
      sls deploy

    • @AhmedBesbes
      @AhmedBesbes 4 ปีที่แล้ว

      @@CompleteCoding Thanks ! I'm sorry I was not clear enough. Sometimes, with python I have very large dependencies (with c bindings), given that the max size is about 250MB, i was wondering if there was a way to circumvent this with serverless.

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

      You can use Lambda Layers or EFS to get around this. Lambda layers would be easier but still has file limits. EFS would allow much larger dependencies.
      I've got a video on Layers (not with serverless though) th-cam.com/video/5a2LS7gNECk/w-d-xo.html
      I've not done a video on adding EFS to lambda yet

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

      @@CompleteCoding thank you mate

  • @HariHaran-nf9ky
    @HariHaran-nf9ky 3 ปีที่แล้ว

    Sir I did upto deployment....after i'm open the url and it show "Missing Authentication Token"

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      That means that either you're probably on the wrong url.

  • @RakeshBitling
    @RakeshBitling 3 ปีที่แล้ว

    Hello sir how to perform in vscode all those cli commands

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      You can open the terminal in VS Code using "View > Terminal" or there are shortcuts. This then works as any other terminal would do.

  • @sedatcanyalcn892
    @sedatcanyalcn892 3 ปีที่แล้ว

    I believe the response object in API Gateway has changed;
    status -> statusCode
    now we have a property isBase64Encoded that we can set to false

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      Yes, it should be statusCode now :) Nice spot

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

    Whenever I deploy and open the url I get an internal server error how do we fix it ?

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

      First look at the cloudwatch logs. Does that indicate why the lambda is erroring.
      You can then wrap your code in a try-catch block and log out the error.
      Once you know the error that is causing it, you can fix it.

  • @rohith_sivapuram4804
    @rohith_sivapuram4804 3 ปีที่แล้ว

    Getting to enter path(0), path(1) after entering sls deploy... Wt to do?

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      I've not seen that error before. Have you entered the path for the endpoints in the serverless.yml file?

    • @753abhishek
      @753abhishek 3 ปีที่แล้ว +1

      use

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

      I think this is due to a conflict with a PowerShell select command. If you use the following it should temporarily remove the alias for the session:
      Remove-Item alias:sls
      After this sls deploy should work as you would expect.

  • @murvinlai
    @murvinlai 3 ปีที่แล้ว

    Is your demo source code on Github?

    • @CompleteCoding
      @CompleteCoding  3 ปีที่แล้ว

      Just added it to the description but here they are for you.
      starting code: github.com/SamWSoftware/ServerlessTH-camSeries/tree/lesson2-S3
      final code: github.com/SamWSoftware/ServerlessTH-camSeries/tree/lesson3-api