How to get item count from DynamoDB?

前端 未结 12 2066
故里飘歌
故里飘歌 2020-12-04 17:15

I want to know item count with DynamoDB querying.

I can querying for DynamoDB, but I only want to know \'total count of item\'.

For example, \'SELECT COUNT(*

相关标签:
12条回答
  • 2020-12-04 17:59
    len(response['Items'])
    

    will give you the count of the filtered rows

    where,

    fe = Key('entity').eq('tesla')
    response = table.scan(FilterExpression=fe)
    
    0 讨论(0)
  • 2020-12-04 18:04

    Similar to Java in PHP only set Select PARAMETER with value 'COUNT'

    $result = $aws->query(array(
     'TableName' => 'game_table',
     'IndexName' => 'week-point-index',
     'KeyConditions' => array(
        'week' => array(
            'ComparisonOperator' => 'EQ',
            'AttributeValueList' => array(
                array(Type::STRING => $week)
            )
        ),
        'point' => array(
            'ComparisonOperator' => 'GE',
            'AttributeValueList' => array(
                array(Type::NUMBER => $my_point)
            )
        )
     ),
     'Select' => 'COUNT'
    ));
    

    and acces it just like this :

    echo $result['Count'];

    but as Saumitra mentioned above be careful with resultsets largers than 1 MB, in that case use LastEvaluatedKey til it returns null to get the last updated count value.

    0 讨论(0)
  • 2020-12-04 18:07

    Replace the table name and use the below query to get the data on your local environment:

    aws dynamodb scan --table-name <TABLE_NAME> --select "COUNT" --endpoint-url http://localhost:8000
    

    Replace the table name and remove the endpoint url to get the data on production environment

    aws dynamodb scan --table-name <TABLE_NAME> --select "COUNT"
    
    0 讨论(0)
  • 2020-12-04 18:08

    Can be seen from UI as well. Go to overview tab on table, you will see item count. Hope it helps someone.

    0 讨论(0)
  • 2020-12-04 18:10

    With the aws dynamodb cli you can get it via scan as follows:

    aws dynamodb scan --table-name <TABLE_NAME> --select "COUNT"
    

    The response will look similar to this:

    {
        "Count": 123,
        "ScannedCount": 123,
        "ConsumedCapacity": null
    }
    

    notice that this information is in real time in contrast to the describe-table api

    0 讨论(0)
  • 2020-12-04 18:10

    In Scala:

    import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
    import com.amazonaws.services.dynamodbv2.document.DynamoDB
    val client = AmazonDynamoDBClientBuilder.standard().build()
    
    val dynamoDB = new DynamoDB(client)
    val tableDescription = dynamoDB.getTable("table name").describe().getItemCount()
    
    0 讨论(0)
提交回复
热议问题