Mar*_*etz 10 amazon-web-services amazon-dynamodb aws-lambda
我正在使用AWS Lambda并尝试向AWS DynamoDB写入内容.我使用以下代码:
var tableName = "locations";
var item = {
deviceId: {
S: event.deviceId
},
timestamps: {
S: event.timestamp
}
}
var params = {
TableName: tableName,
Item: item
};
dynamo.putItem(params, function(err, data) {
if (err) {
context.fail(new Error('Error ' + err));
} else {
context.success(null);
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
returns Error ValidationException: One or more parameter values were invalid: Type mismatch for key deviceId expected: S actual: M
Run Code Online (Sandbox Code Playgroud)
Mar*_*etz 33
发生这种情况是因为Nodejs的aws sdk发生了变化!
如果您正在使用:
var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();
Run Code Online (Sandbox Code Playgroud)
那么putItem调用(以及大多数其他调用)的参数已经改变,而是需要:
var tableName = "locations";
var item = {
deviceId: event.deviceId,
timestamp: event.timestamp,
latitude: Number(event.latitude),
longitude: Number(event.longitude)
}
var params = {
TableName: tableName,
Item: item
};
Run Code Online (Sandbox Code Playgroud)
阅读所有关于新sdk的信息:https://github.com/awslabs/dynamodb-document-js-sdk
| 归档时间: |
|
| 查看次数: |
14216 次 |
| 最近记录: |