1

我正在尝试使用aws-sdk与 AWS 的 dynamodb 进行交互

这是我的代码:

DynamoDB.putItem({
    "TableName": tblName,
    "Item": {
        "UserId": { "N": obj.user_id.toString() },
        "Identifier": { "S": obj.identifier },
        "ReferralToken": { "S": obj.referral_token },
        "CampaignId": { "N": obj.campaign_id.toString() },
        "FirstName": { "S": obj.first_name },
        "LastName": { "S": obj.last_name },
        "Gender": { "S": obj.gender },
        "BirthDate": { "S": obj.birthdate },
        "Username": { "S": obj.username },
        "MobileNumber": { "S": obj.mobile_number },
        "PostalCodeText": { "S": obj.postal_code_text },
        "Classification": { "S": obj.classification },
        "DeliveryEmail": { "S": obj.delivery_email.toString() },
        "DeliverySMS": { "S": obj.delivery_sms.toString() }
    }
}, function (err, data) {
    console.log(err);
    console.log(data);
});

我收到的错误是

{ [ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes]
  message: 'Supplied AttributeValue is empty, must contain exactly one of the supported datatypes',
  code: 'ValidationException',
  time: Fri Oct 10 2014 10:15:25 GMT-0500 (CDT),
  statusCode: 400,
  retryable: false }

不知道我做错了什么

4

2 回答 2

3

根据Put Item文档,

添加项目时,主键属性是唯一必需的属性。属性值不能为空。字符串和二进制类型属性的长度必须大于零。集类型属性不能为空。具有空值的请求将被拒绝,但有ValidationException异常。

因此,请确保所有值都不为空,并且所有字符串长度都大于零。

于 2014-10-15T12:30:04.930 回答
0

就我而言,由于映射模板发送的参数无效,我遇到了同样的问题。

#set($inputRoot = $input.path('$'))
{ 
   "userId": "$input.params('userId')",
   "userEmail": "$input.params('userEmail')",
   "userName": "$input.params('userName')",
   "userPassword": "$input.params('userPassword')"
}

这里我发送了额外的参数 userId ,这就是发生错误的原因。所以请检查您的映射模板,您可能会这样做。

于 2017-03-24T06:02:15.197 回答