3

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!!

Bharath Kuppala
  • 176
  • 1
  • 3
  • 14
  • DynamoDB has `Count` and `ScannedCount` (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.Count), but I am not sure if it is applicable on AppSync queries. – vahdet Oct 20 '18 at 10:59

2 Answers2

1

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.

Vasileios Lekakis
  • 5,492
  • 2
  • 15
  • 17
  • Hi, @Vasileios Lekakis thanks for your resourceful replay. Apart from that, I have also tried querying out the values based on Attributes ie in the name field I inserted the same name called Bharath for 5 times and then later tried to query based on name saying where name and then return the count. I might have written the query wrong could you please guide how can this be achieved using resolvers in appsync. Any use full resource is much appreciated. Thank you – Bharath Kuppala Sep 10 '18 at 16:28
0

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

Riki Chou
  • 509
  • 1
  • 3
  • 13