Well, so we have been successfully able to add an update data in Dynamo dB. Now let's let's try to get all these information from Dynamo dB of course we are going to use the same AWS SDK to get all those informations let's let's review what are different methods to get data from dynamodb. So get method returns a set of attributes for the item with the given primary key. Of course in this case what we are after is whole data from Dynamo DB itself. We can use query but again, we need index name and key condition expression to get all those data from dynamodb. On this occasion, what we are going to do is we are going to use the scan method of a dynamodb table dynamodb document to get all those data from dynamodb eventually table.
So just a quick recap, and what what, what is all methods are supposed to do. And feel free to refer this dynamodb SDK documentation. And let's use scan in this scan on this occasion. So what we are going to do is returns all the informations from this dynamodb table. So what we are going to use we are We don't need any parents in this case because we are not passing any information. But let's create a function a lambda function, get inventory and let's keep there on time 8.1 or what we have been using an existing role.
Let's choose the same roll because it has got access full access to dynamodb table itself and we saw we are free to perform any actions. So let's paste everything from the previous function. We don't take params in this case, of course, but we need a table name. So let's let's give the table name in this case. And since we have defined table name as an environment variable In all other cases, so let's stick with that approach itself. And it is easy to you know kind of make your code readable and usable, legible.
So, what we are going to use scan in this case and we are not passing any expiration condition or condition we can use query method if we if we want to query and, of course, we can use for that expression with scan function so, we can actually Can we can use expression attribute values the same we used in the case of date. We can use all those methods here to filter by an expression or something but let's let's in this case, let's test a bit. let's configure we don't have to pass any request body. And just even if you give the request body it, it doesn't hurt because you are not going to you know, consume those request body and it doesn't matter. Let's test it. And see we are getting all those informations from dynamodb here, which is pretty cool.
So we have added information, we have updated informations now we are reading all those data from our dynamodb table inventory. And that that that looks great and that is also kind of We're just speaking with data dot items. So we don't get items added as it was earlier. But now we see we'll just get the array of items. And since we are since we have defined data, so that's why I did as in JSON properties coming here, and you can go and verify everything what you are reading from your dynamodb itself is in stock. Let's Let's change a couple of things and try to read information again and let's actually apply Filter Expression here.
So what we want to do here is Don't show me all those data or all those inventories which are not in stock. So what we are going to apply here is we are going to filter by is in stock property. So is in stock is a book In property and we can pass as an Filter Expression. So, once we once we are running this Dynamo DB query, it checks the Filter Expression and it will exclude or include all those part of those Filter Expression itself. In this case we are going to exclude inventors which are not in stock here. So what we are going to do give me inventories which are in stock and if you see we are going to get only two items this time rather than three because it's in stock to reason ID One, two, both are in stock item three is not in stock and so we are getting it.
It is quite fun so far. I hope you are enjoying this and I'll see you in the next lecture.