How to get the total number of records count present in dynamodb using Resolver in Appsync

Viewed 3193

I am new to Dynamodb and Appsync I have one table named User with fields id and name as follow

type User {
id: ID! // auto-generated
name: String }

By using the mutation I inserted 5 records. Now my query is how do I get the count of the number of records present in the Dynamodb table using the Appsync request mapping template(Resolver) can be any type of template(ie query, scan, batchGetitem etc).

Thanks in advance!!

2 Answers

There's probably not good way of achieving this. Someone could claim that scan see how much you get back but certainly this won't work for really large numbers.

DynamoDB itself i think gives you only an estimation about the total number of items in the table. I don't think this is exposed from AppSync though.

I think you are looking for scannedCount

query getUsers{
    ListUsers{
      items{
        id
        name
      }
      scannedCount
    }
}

in the request resolver choose the "list item" template and in the result resolver choose "return single result" template

Related