Dynamodb 获取项目出错
Dynamodb get item is erroring out
使用 javascript aws sdk
我的table定义如下:
resources:
Resources:
ImagesTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
- AttributeName: "deviceId"
AttributeType: "S"
- AttributeName: "timeStamp"
AttributeType: "N"
KeySchema:
- AttributeName: "deviceId"
KeyType: "HASH"
- AttributeName: "timeStamp"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.settings.${self:custom.myStage}.ITEMS_DYNAMODB_TABLE}
StreamSpecification:
StreamViewType: NEW_IMAGE
我尝试 运行 查询并获取与字符串匹配的所有设备。
我的参数对象是
const params: DynamoDB.DocumentClient.GetItemInput = {
TableName: eventLogTable,
Key: {deviceId: 'device12345'}
};
我的电话是
return this.client.get(params).promise()
.then(result => {
return result;
});
在日志文件中,我看到以下错误:
2019-06-21T17:23:27.878Z cc865442-8604-4f5c-8099-72eba87d9b2b query params right before going in { TableName: 'sls-basic-operations-items-dev',
Key: { deviceId: 'device12345' } }
2019-06-21T17:23:27.904Z cc865442-8604-4f5c-8099-72eba87d9b2b { ValidationException: The provided key element does not match the schema
不明显我的错误是什么?
想法?
这里的问题似乎是您在使用 dynamodb 客户端 Get 操作时仅指定了哈希键。由于您的 table 有一个范围键(排序键),您还应该在 Getitem 请求中指定它
如果您只想使用散列键搜索记录,您应该使用查询操作。
参数 = {
表名:'eventLogTable',
KeyConditionExpression: '#deviceId = :deviceId'
};
DynamoDB.DocumentClient.query
(参数,
使用 javascript aws sdk
我的table定义如下:
resources:
Resources:
ImagesTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
- AttributeName: "deviceId"
AttributeType: "S"
- AttributeName: "timeStamp"
AttributeType: "N"
KeySchema:
- AttributeName: "deviceId"
KeyType: "HASH"
- AttributeName: "timeStamp"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:custom.settings.${self:custom.myStage}.ITEMS_DYNAMODB_TABLE}
StreamSpecification:
StreamViewType: NEW_IMAGE
我尝试 运行 查询并获取与字符串匹配的所有设备。
我的参数对象是
const params: DynamoDB.DocumentClient.GetItemInput = {
TableName: eventLogTable,
Key: {deviceId: 'device12345'}
};
我的电话是
return this.client.get(params).promise()
.then(result => {
return result;
});
在日志文件中,我看到以下错误:
2019-06-21T17:23:27.878Z cc865442-8604-4f5c-8099-72eba87d9b2b query params right before going in { TableName: 'sls-basic-operations-items-dev',
Key: { deviceId: 'device12345' } }
2019-06-21T17:23:27.904Z cc865442-8604-4f5c-8099-72eba87d9b2b { ValidationException: The provided key element does not match the schema
不明显我的错误是什么? 想法?
这里的问题似乎是您在使用 dynamodb 客户端 Get 操作时仅指定了哈希键。由于您的 table 有一个范围键(排序键),您还应该在 Getitem 请求中指定它 如果您只想使用散列键搜索记录,您应该使用查询操作。 参数 = { 表名:'eventLogTable', KeyConditionExpression: '#deviceId = :deviceId' }; DynamoDB.DocumentClient.query (参数,