python DynamoDB扫描操作不返回所有记录

Rob*_*ert 0 python amazon-web-services amazon-dynamodb

在 DynamoDB 表中,我在没有任何过滤器的情况下应用时有161712 条记录,我只收到了 10589 条扫描计数值

这是 mytable 元

{
  "AttributeDefinitions": [
    {
      "AttributeName": "question_id",
      "AttributeType": "N"
    },
    {
      "AttributeName": "timestamp",
      "AttributeType": "S"
    }
  ],
  "TableName": "users_answers",
  "KeySchema": [
    {
      "AttributeName": "timestamp",
      "KeyType": "HASH"
    },
    {
      "AttributeName": "question_id",
      "KeyType": "RANGE"
    }
  ],
  "TableStatus": "ACTIVE",
  "CreationDateTime": "2017-09-12T12:33:22.615Z",
  "ProvisionedThroughput": {
    "LastIncreaseDateTime": "2017-09-12T16:46:26.742Z",
    "NumberOfDecreasesToday": 0,
    "ReadCapacityUnits": 80,
    "WriteCapacityUnits": 80
  },
  "TableSizeBytes": 16014441,
  "ItemCount": 161712
}
Run Code Online (Sandbox Code Playgroud)

当我做上面表的扫描操作时只会得到 10589 条记录

table = dynamo.get_table('answer_options')
x    = table.scan()
Run Code Online (Sandbox Code Playgroud)

请建议我如何从表中获取整个记录

环境:python 3.5.1,flask dynamodb

提前致谢

das*_*mug 7

DynamoDB 每个请求仅返回 1MB。您必须遍历并发出多个请求,直到获得整个数据集。

来自DynamoDB 文档

DynamoDB 对扫描操作的结果进行分页。通过分页,扫描结果被分成大小为 1 MB(或更小)的数据“页面”。应用程序可以处理第一页结果,然后是第二页,依此类推。

单次扫描将仅返回符合 1 MB 大小限制的结果集。要确定是否有更多结果,并一次检索一页,应用程序应执行以下操作:

  1. 检查低级扫描结果:

    • 如果结果包含 LastEvaluatedKey 元素,请继续执行步骤 2。
    • 如果结果中没有 LastEvaluatedKey,则没有更多的项目要检索。
  2. 构造一个新的 Scan 请求,使用与前一个相同的参数——但这次,采用步骤 1 中的 LastEvaluatedKey 值,并将其用作新 Scan 请求中的 ExclusiveStartKey 参数。

  3. 运行新的扫描请求。

  4. 转到步骤 1。