3
votes

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
DynamoDB has Count and ScannedCount (docs.aws.amazon.com/amazondynamodb/latest/developerguide/…), but I am not sure if it is applicable on AppSync queries. - vahdet

2 Answers

1
votes

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.

0
votes

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