我在 Dynamodb 中对全局二级索引的分页有疑问:/
我的 DynamoDB 架构是:
Resources:
ImportsTable:
Type: AWS::DynamoDB::Table
Properties:
# Generate a name based on the stage
TableName: ${self:service}-${self:custom.stage}-imports
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: fixedKey
AttributeType: S
- AttributeName: timestamp
AttributeType: N
KeySchema:
- AttributeName: id
KeyType: HASH
StreamSpecification:
StreamViewType: NEW_IMAGE
ProvisionedThroughput:
ReadCapacityUnits: ${self:custom.app.tableThroughput.imports}
WriteCapacityUnits: ${self:custom.app.tableThroughput.imports}
TimeToLiveSpecification:
AttributeName: expirationTime
Enabled: true
GlobalSecondaryIndexes:
- IndexName: time-index
KeySchema:
- AttributeName: fixedKey
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: ${self:custom.app.tableThroughput.imports}
WriteCapacityUnits: ${self:custom.app.tableThroughput.imports}
SSESpecification:
SSEEnabled: true
我的查询参数:
let params = {
TableName: process.env.importsTableName,
IndexName: 'time-index',
KeyConditionExpression: 'fixedKey = :fk',
Limit: 5,
ProjectionExpression: "timeBasedId, importFileS3Key, meta, #st, #ch, success, errors, #ty, #id, email",
ScanIndexForward: true,
ExpressionAttributeNames: {
"#ch": "Attributes",
"#st": "status",
"#ty": "type",
"#id": "identity",
},
ExpressionAttributeValues: {
":fk" : "fixedKey",
},
};
当我运行这个时,我得到一个回应:
LastEvaluatedKey: {
id: 88de14a0-2475-11e9-a0ee-d317558aa61b
fixedKey: fixedKey
timestamp: 1548842283754
}
所以对于下一个电话,我在我的参数中添加了这个:
ExclusiveStartKey: {
id: event.queryStringParameters.id,
}
event.queryStringParameters.id看起来像一个很好的 Key
88de14a0-2475-11e9-a0ee-d317558aa61b
但是当我运行它时,我得到一个 500 错误和这条消息:
The provided starting key is invalid
我发现一条线索告诉我将整个 LastEvaluatedKey 添加到请求中,但是当我使用以下命令运行查询时:
ExclusiveStartKey: {
id: event.queryStringParameters.id,
fixedKey: event.queryStringParameters.fixedKey,
timestamp: event.queryStringParameters.timestamp
}
当 event.queryStringParameters 看起来像:
{ fixedKey: 'fixedKey',
id: '88de14a0-2475-11e9-a0ee-d317558aa61b',
timestamp: '1548842283754' }
我收到此错误:
The provided key element element does not math the schema