我想使用promises在JavaScript中使用aws-sdk.
而不是默认的回调样式:
dynamodb.getItem(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Run Code Online (Sandbox Code Playgroud)
我想要使用承诺风格:
dynamoDb.putItemAsync(params).then(function(data) {
console.log(data); // successful response
}).catch(function(error) {
console.log(err, err.stack); // an error occurred
});
Run Code Online (Sandbox Code Playgroud) 我正在使用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)