DynamoDB Scan Count

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html

If the size of the Scan result set is larger than 1 MB, ScannedCount and Count represent only a partial count of the total items. You need to perform multiple Scan operations to retrieve all the results (see Paginating the Results).

Items are first fetch and then counted, and if the size of fetched items exceed 1MB even ‘count’ will be paginated

aws dynamodb scan \
    --table-name  \
    --filter-expression "#v = :num" \
    --expression-attribute-names '{"#v": "fieldName"}' \
    --expression-attribute-values '{":num": {"N": "123"}}' \
    --select "COUNT"

will show

{
    "Count": 2945,
    "ScannedCount": 7874,
    "ConsumedCapacity": null
}

ScannedCount is total count and Count is the number of items which are filtered by given expression (fieldName=123).

https://stackoverflow.com/questions/56880639/how-to-get-total-number-of-pages-in-dynamodb-if-we-set-a-limit

Neither “Scan” (to read the entire table) nor “Query” (to read all the items with the same partition key) operations return an estimate on how many total results there are. In some cases (e.g., when a FilterExpression is provided), there is no efficient way for DynamoDB to do this estimation. In other cases there may be a way for DynamoDB to provide this information, but it doesn’t.