Create an API to get data from your DynamoDB Database

  Рет қаралды 22,813

Complete Coding - Master AWS Serverless

Complete Coding - Master AWS Serverless

4 жыл бұрын

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
@JeanYvesP
@JeanYvesP 4 жыл бұрын
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 жыл бұрын
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
@devprakash5320
@devprakash5320 2 жыл бұрын
I'm loving this whole series
@CompleteCoding
@CompleteCoding 2 жыл бұрын
Really glad to head that
@jax_cph
@jax_cph 3 жыл бұрын
loving you vids Sam.. really eye operning what you can do with serverless + aws watching all of your vids now :-)
@CompleteCoding
@CompleteCoding 3 жыл бұрын
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!
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Glad you liked it!
@vinodsamy1725
@vinodsamy1725 3 жыл бұрын
Splendid Man!! thanks a lot.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
My pleasure
@shadmanmartinpiyal4057
@shadmanmartinpiyal4057 3 жыл бұрын
I feel I am lucky that I found this playlist.
@CompleteCoding
@CompleteCoding 3 жыл бұрын
From your comments it feels like you've watched the whole way through!
@shadmanmartinpiyal4057
@shadmanmartinpiyal4057 3 жыл бұрын
@@CompleteCoding yes Indeed!
@ABHISHEK0058
@ABHISHEK0058 3 жыл бұрын
Same
@yenaingoo421
@yenaingoo421 4 жыл бұрын
Thanks a lot Sir
@CompleteCoding
@CompleteCoding 4 жыл бұрын
Most welcome
@olofnuggets5936
@olofnuggets5936 Жыл бұрын
Can you do more videos like this :) can you do a complete Project video that will help allot
@AmruAshik
@AmruAshik 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'});
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Nice spot
@MagicJF
@MagicJF 2 жыл бұрын
Thanks! :)
@alexgochenour8740
@alexgochenour8740 4 жыл бұрын
This is really valuable content! Where's your patreon page?
@CompleteCoding
@CompleteCoding 4 жыл бұрын
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 }
@lfellidev
@lfellidev 2 жыл бұрын
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.
@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 kzfaq.info/get/bejne/d82lh8R-tq2lc3k.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.
@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
@cioccari11
@cioccari11 3 жыл бұрын
is it possible to create this API for using offline (local) with also serverless and dynamodb offline?
@CompleteCoding
@CompleteCoding 3 жыл бұрын
Definitely. Here's a video on it kzfaq.info/get/bejne/q9KPa5iby7OUn6M.html
@cioccari11
@cioccari11 3 жыл бұрын
@@CompleteCoding thanks for that bro, excellent content. Keep going!
@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
@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
@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 3 жыл бұрын
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();
Adding New Data to your DynamoDB Database
14:45
Complete Coding - Master AWS Serverless
Рет қаралды 10 М.
Securing Your Serverless API With API Keys
14:21
Complete Coding - Master AWS Serverless
Рет қаралды 10 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 18 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 39 МЛН
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 9 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 39 МЛН
Oracle is destined to beat Amazon at cloud database: Larry Ellison
8:47
Creating an API with Serverless - API Gateway and AWS Lambda
14:23
Complete Coding - Master AWS Serverless
Рет қаралды 30 М.
What is a DynamoDB LSI (Local Secondary Index) ?
9:20
Be A Better Dev
Рет қаралды 64 М.
Adding and Getting Files from Amazon S3 with Serverless.
21:39
Complete Coding - Master AWS Serverless
Рет қаралды 14 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 560 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 348 М.
Create a Serverless Database - DynamoDB with the Serverless Framework
9:59
Complete Coding - Master AWS Serverless
Рет қаралды 18 М.
ноутбуки от 7.900 в тг laptopshoptop
0:14
Ноутбуковая лавка
Рет қаралды 3,6 МЛН