How to Build a Serverless REST API with Node.js, TypeScript, and AWS DynamoDB

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

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

  • @solomontemitayo3772
    @solomontemitayo3772 2 года назад +3

    Thank you man, you saved me hours of study

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад +2

      Glad I could help!

    • @solomontemitayo3772
      @solomontemitayo3772 2 года назад +1

      @@tomasztarnowski4434 is there a way to scan dynamodb to get the list ordered by LIFO

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад +1

      Hey Solomon, there is a way but you need to either make the field you want to sort by a "Sort Key" or create a secondary index specifying that field again as a "Sort Key", then with the usage of Query method you can utilise ScanIndexForward parameter to get items in order

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

    Very useful, thanks. Had to run "npm install" before deploy after adding uuid and then yup dependencies, or it would fail on the server once API is called since after yarn alone apparently packages are not being deployed.

  • @jordivallverdu6200
    @jordivallverdu6200 Год назад +1

    Would be nice to have a second part with authentication and authorization, also with some fron end fro users to request acces. Just an idea ! Thanks fro the great video

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

    Thanks ! You validation part is very valuable ❤

  • @sciency_stuff
    @sciency_stuff Год назад +1

    Hey dude. This video was so useful. I have one question though.
    Where's the DB located?
    When I sign up to my IAM and go to DynaoDB I do not see ProductsTable.
    Then where is it located?

    • @sciency_stuff
      @sciency_stuff Год назад +1

      Ohh Damn! The table is created in the AWS location specified in the config.
      Thanks a ton :)

    • @tomasztarnowski4434
      @tomasztarnowski4434  Год назад +1

      That is correct! I'm happy you've managed to figure this out yourself!

  • @martindanielperezpuchuri3112
    @martindanielperezpuchuri3112 2 года назад +2

    new sub, great video, your wallpaper is 10/10

  • @emiremark2889
    @emiremark2889 2 года назад +1

    Thank you .. this was a great video and got me started. great content will watch all other videos :)

  • @luuquanghung
    @luuquanghung 2 года назад +1

    Thanks for the great video.
    I got the error: The CloudFormation template is invalid: Template error: instance of Fn::GetAtt references undefined resource ProductsTable.
    How can I fix it?

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад

      Hey Luu,
      Have you got "resources" section defined in serverless.yml with correct indentations like here:
      github.com/ttarnowski/serverless-product-api/blob/main/serverless.yml
      ?

  • @eR1cK92
    @eR1cK92 2 года назад +1

    I can use that syntsx on the events within framework serverless? Mybresources on aws are deployed by terraform and just need yo creare the code for lambda function and tests
    And my api is a api websockets

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад

      if your resources are deployed separately you need to link them in iamRoleStatements to give lambdas permissions to access them.
      If your api is websockets it works differently to the one presented in the video. Although I'll have a new video out soon specifically about API Gateway Websockets. I hope it'll help :)

    • @eR1cK92
      @eR1cK92 2 года назад +1

      @@tomasztarnowski4434 I'm waiting for that

  • @nwigweuzochukwu6089
    @nwigweuzochukwu6089 2 года назад +1

    Can we see a similar video which follows a aTDD approach?

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад

      I'm a big fan of TDD myself and very often use this approach in my professional work, so yeah definitely there will be videos in the future where I build something with tests.

  • @ol1175
    @ol1175 Год назад +1

    Wow, thank you so much. Really love your tutorials. Would be really nice to create an authoriser for our API gateway!
    Thank you mate!

    • @tomasztarnowski4434
      @tomasztarnowski4434  Год назад +1

      Thank you, I'm glad you liked the video. Authentication in serverless will be most likely the next topic. There should be a new video about it soon.

  • @M.ojo.M
    @M.ojo.M 9 месяцев назад

    Hi bro, I have a company as AWS solutions architect, I am still in training, I dont have knowledge of html/css/js/node.js rest-api dynamo.db, is it necessary for me to learn all these then create a application and test in AWS ?

  • @mattriese8143
    @mattriese8143 2 года назад +2

    Can you explain why you use .promise() but don't set that promise to a variable to process fulfilled/rejected states? For example, in createProduct() you have:
    await docClient
    .put({
    TableName: tableName,
    Item: product,
    })
    .promise();
    You add it at 15:30, but I don't really understand what the .promise() is doing

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад +3

      hey Matt, very good question ".promise()" method is a part of AWS SDK and it turns entire expression's result (in this case docClient.put(...)) into a javascript Promise object, so you can use either older .then(), .catch() syntax or new async await.
      If I hadn't put .promise() after "put" method I wouldn't have been able to await for this operation to complete.
      Here's also good explanation in AWS docs with older syntax hopefully it'll help you to grasp it:
      docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/using-promises.html
      And here how to rewrite .then(), .catch() to async-await:
      developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await#rewriting_promise_code_with_asyncawait

    • @mattriese8143
      @mattriese8143 2 года назад

      @@tomasztarnowski4434 ah, ok! So if that async docClient.put() call fails, would the catch block (that eventually) wraps it catch the error? what would happen if it was never wrapped in a try/catch block? (thanks for your help!!)

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад +1

      if you want to catch that error and have some specific response sent from lambda you can put it in a try-catch block however if you don't in aws lambda environment it is going to fail, log an error in cloudwatch and respond with 500 status code and generic internal server error response body :)

  • @vatsalpatel3669
    @vatsalpatel3669 Год назад +1

    very simple and well explained (:

  • @spacetium1312
    @spacetium1312 Год назад

    each time I deploy using serverless deploy I get this error after some time loading
    Serverless: Uploading service products-api.zip file to S3 (16.88 MB)...
    Serverless: Recoverable error occurred (Your socket connection to the server was
    not read from or written to within the timeout period. Idle connections will be closed.), sleeping for ~5 seconds. Try 1 of 4
    I searched everywhere and no solution

  • @tosinolugbenga2904
    @tosinolugbenga2904 Год назад +1

    I got an error Stack [product-api-dev] does not exist

  • @louissasha
    @louissasha 2 года назад +1

    great tutorial

  • @TCErnesto
    @TCErnesto 2 года назад +1

    you're not using Express.js right?

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад +1

      Hey, no, for lambda function you don't need to use express as it's a simple function that takes a request object and is supposed to return a response object. However you can still use express.js syntax if you'd like by using this wrapper library: github.com/vendia/serverless-express.

  • @rakeshrockb
    @rakeshrockb Год назад

    Thank you so much.

  • @ctk41sphnvti
    @ctk41sphnvti Год назад

    thanks your tutorial

  • @lordpablo1985
    @lordpablo1985 2 года назад +1

    Don't use aws-sdk, its outdated. Use the modular v3 SDK.

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад

      I'll be switching to v3 SDK since it's recommended by AWS now, although this example of an serverless app is still going to work just fine with v2

    • @lordpablo1985
      @lordpablo1985 2 года назад

      @@tomasztarnowski4434 now? It's been recommended for nearly 2 years!

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад +1

      I've always been very conservative with using the newest versions until they reach a proper stability.

    • @lordpablo1985
      @lordpablo1985 2 года назад +1

      @@tomasztarnowski4434 same here. V3 has been deemed stable for long enough now though.

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад

      Agree.

  • @browaruspierogus2182
    @browaruspierogus2182 2 года назад

    Amazon SDKs tend to get very ugly and abandoned in future

    • @tomasztarnowski4434
      @tomasztarnowski4434  2 года назад

      I wouldn't say it gets abandoned. They have a maintenance policy in place:
      docs.aws.amazon.com/sdkref/latest/guide/maint-policy.html
      also, there's a communication channel for any deprecation updates