0

我在將PutItem請求發送到DynamoDB時遇到問題。我知道類似的問題已被回答here,但似乎我在這裏沒有空值。AWS DynamoDB問題與PutItem。什麼是適當的JSON格式?

我的JSON是:

{ 
    "TableName":"Unity", 
    "Item":{ 
     "id":{ 
      "S":"73709359-ac78-46a0-8ca6-414393e33339" 
     }, 
     "Session":{ 
      "S":"b6ba8b6d-ce27-4585-aee5-b9a2393e54da" 
     }, 
     "Pos":{ 
      "X":{ 
       "S":"-16.8" 
      }, 
      "Y":{ 
       "S":"-4.492812" 
      } 
     }, 
     "Time":{ 
      "S":"7/27/2017 3:21:25 PM" 
     } 
    } 
} 

和錯誤是一個ValidationException:

Supplied AttributeValue is empty, must contain exactly one of the supported datatypes 

任何人都知道這是怎麼回事?

回答

1

請嘗試下面的代碼。我添加了數據類型地圖的屬性Pos

var dynamoDB = new AWS.DynamoDB; 

var params = { 
    TableName: "Unity", 
    Item: { 
     "id": { 
      S: "73709359-ac78-46a0-8ca6-414393e33339" 
     }, 
     "Session": { 
      S: "b6ba8b6d-ce27-4585-aee5-b9a2393e54da" 
     }, 
     "Pos": { 
      M: { 
       "X": { 
        S: "-16.8" 
       }, 
       "Y": { 
        S: "-4.492812" 
       } 
      } 
     }, 
     "Time": { 
      S: "7/27/2017 3:21:25 PM" 
     } 
    } 
}; 

console.log("Adding a new item..."); 
dynamoDB.putItem(params, function (err, data) { 
    if (err) { 
     console.error("Unable to add item. Error JSON:", JSON.stringify(err, 
      null, 2)); 
    } else { 
     console.log("Added item:", JSON.stringify(data, null, 2)); 
    } 
});