Create an API to get data from your DynamoDB Database

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2019
  • In this video we'll be making our second API endpoint. We'll learn about the aws-sdk and how we can use it to access data from our dynamo table.
    By the end of this video you'll know how to:
    Creating multiple endpoints on an API
    Give permission to a lambda to access DynamoDB
    Create a reusable Dynamo wrapper to make accessing data easier
    Code available at
    github.com/SamWSoftware/Serve...
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    I'm loving this whole series

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

    Thanks Sam! I'm going over all your videos. Really nice!

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

      Thanks Jean. I'm glad you're finding them useful

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

    Hey Sam, just wanted to say I really enjoyed your videos so far. This area of coding is missing some good old fashioned explanations and examples, and you fill the gap perfectly. Looking forward to more content!

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

      Thanks Omer, glad you're enjoying the content

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

    I feel I am lucky that I found this playlist.

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

    Splendid Man!! thanks a lot.

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

    for people getting dynamobd.documentclient is not a constructor in the lambda function logs use, var documentClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});

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

    loving you vids Sam.. really eye operning what you can do with serverless + aws
    watching all of your vids now :-)

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

      Thanks Jax. Serverless is so powerful and flexible.
      There are projects I've down with clients where we build in 3 days a product that would have been months of work without serverless.

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

    Excellent ! thank you!

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

    Thanks a lot Sir

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

    Can you do more videos like this :)
    can you do a complete Project video that will help allot

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

    In new serverless version the correct way is:
    iam:
    role:
    statements:
    - Effect: "Allow"
    Action:
    - "dynamodb:*"
    Resource: '*'

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

      You should still be able to do the method shown with serverless V3.

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

    This is really valuable content! Where's your patreon page?

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

      Thanks Alex. I don't have a patreon page but liking and commenting on the videos is a great way to help me out. Checked out your videos too, they're really good and clear. Keep up the great work

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

    Hi Sam, I am getting the following error:
    `await is only valid in async function `
    The above error is for `const user = await Dynamo.get(ID, tableName).catch(err => {.....`
    Excellent videos. These are really helpful.

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

      Got it. I didn't declare the handler function in getUser as async. :D

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

      I've done this so many times. I've now set up vs code snippets to set up new handlers

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

    Hi Sam, I hope you are doing well. In the get response of my lambda call, I get undefined text being returned for those values which are null/empty in DynamoDB. Is there a way for me to ignore/not pass these values as a part of my get response.

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

      There isn't a way that I know if in Dynamo to do this, but you can easily do it in code.
      Object.entries(data).map(([key, value]) => value === null && delete data[key])
      or you could convert this to a function
      const removeNull = data => {
      Object.entries(data).map(([key, value]) => value === null && delete data[key])
      return data
      }

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

    Great video! What if I have an application that interacts w/ dynamodb through lambda, and I get ProvisionedThroughputExceededException when in actuality dynamadb is not producing such error. Any suggestion please?

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

      That means that your dynamo is probably set to "provisioned capacity" and you're using more than what is set.
      If you've set a read capacity of 1, that's about 2 requests up to 4kb per second. If you try and do a third you'll get that error.
      To fix this either increase the capacity or change the table to be 'on demand'. It costs more but scales super fast and doesn't cost you when you're not using it.

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

      @@CompleteCoding I thought about what you said, but the provisioned throughput exceeded exception is not in the Dynamodb log. It's only the application reporting the error erroneously. I wonder if permission issues would cause that.

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

      @@renejacques8288 I would be surprised if a permissions issue would return that error message.
      googling that error message always says that it's a Dynamo capcity issue.

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

      @@CompleteCoding OK. By chance would you know any good study video/material for someone going for the AWS solutions architect and the developer's associate exams?

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

      @@renejacques8288 Go to Udemy and search for the exam you're taking. There are some with thousands of 5* reviews.
      The ones I've done previously will be out of date now

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

    How to send array of json objects in post method

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

      First check out my video on creating a POST endpoint th-cam.com/video/AguTaMQGACE/w-d-xo.html
      Using that video, you would just need to change the logic in your Lambda. The event body will now be an array of objects so you can do something like:
      const arrayOfNewUsers = JSON.parse(event.body)
      const promiseArray = arrayOfNewUsers.map(async (user) => {
      const newUser = await Dynamo.write(user, tableName)
      return newUser
      });
      const users = await Promise.all(promiseArray);
      If you pass three objects in the array, it will 'map' over them and each one will write to dynamo. You end up with three promises so you just use 'Promise.all' to make sure they all succeed.

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

    is it possible to create this API for using offline (local) with also serverless and dynamodb offline?

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

      Definitely. Here's a video on it
      th-cam.com/video/ul_85jfM0oo/w-d-xo.html

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

      @@CompleteCoding thanks for that bro, excellent content. Keep going!

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

    I get a response to 502 bad gateway for several times trying. I don't know what happened. I sure the code is the same with this tutorial. Somebody can help me? thanks.

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

      If you go into the lambda in the AWS console and the 'monitoring' tab. Have a look at the recent invocations. You should be able to see anything that is console.log() in the code. This should point you in the right direction

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

    is there a way to fetch the whole table?

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

      You could use a Scan. This is not advised though as it isn't a very optimised request. You also only get back the first 1MB of data, and then you'd have to subsequently make requests until you've got the whole table.
      The other way is to query each index in your table.
      Either way it's not a process that you want to be doing. Maybe you could redesign your app so you don't have to read a whole table at once.

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

      @@CompleteCoding thank you for the scan option..i also figured out that scan was an option to fetch the whole data contents- if I need to plot in a table..but if i need to plot entity wise or date wise i'll use query thanks for the tips

  • @AyushYadav-mw8pd
    @AyushYadav-mw8pd 2 ปีที่แล้ว

    I want the same code for get method but in python

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

      I've not got any Python code I can share at the moment but this page has a lot of good starter Python code
      docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Python.03.html

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

    {"message": "Internal server error"} i get this error

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

      If you look in the lambda logs then you should find out why the function has errored

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

      I was getting similar error. Looked up Lambda logs and found out my Dynamo.js function was failing because of a typo in AWS.DynamoDB.DocumentClient();