我想從DynamoDB AWS獲取單個項目,但無法弄清楚如何使用散列和範圍鍵指定它。下面是是describeTable和掃描輸出:爲什麼getItem()返回「Invalid attribute value type」?
// describeTable output:
{
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "timepost",
"AttributeType": "N"
},
{
"AttributeName": "addr",
"AttributeType": "S"
}
],
"TableName": "Scratch",
"KeySchema": [
{
"AttributeName": "timepost",
"KeyType": "HASH"
},
{
"AttributeName": "addr",
"KeyType": "RANGE"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2017-08-24T07:08:19.650Z",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T00:00:00.000Z",
"LastDecreaseDateTime": "1970-01-01T00:00:00.000Z",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"TableSizeBytes": 32,
"ItemCount": 1,
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Scratch"
}
}
// scan output:
{
"Items": [
{
"addr": "1.1.1.1:443",
"ms": 67,
"timepost": 12321340
}
],
"Count": 1,
"ScannedCount": 1
}
,這裏是我的getItem()代碼和錯誤輸出:
docClient.get({
TableName: "Scratch",
Key: {
timepost: {N: '12321340'},
addr: {S: '1.1.1.1:443'}
}}, opComplete);
err: {
"message": "Invalid attribute value type",
"code": "ValidationException",
"time": "2017-08-26T15:56:59.938Z",
"requestId": "f9d94f20-f22d-4141-be06-2eaba1eee5a1",
"statusCode": 400,
"retryable": false,
"retryDelay": 26.507308215655236
}
我在做什麼錯?
這一個給我同樣的錯誤,「無效的屬性值類型」。 – noctonura