我在AWS中创建了一个API,该API调用Lambda并将模拟用户添加到DynamoDB。该API将通过Lambda将请求正文传递给Dynamo,但是Lambda函数仍然失败。它按预期执行,但不理解为什么会出现错误?我是AWS的新手。
我尝试查看我的映射模板,模型,集成请求和集成响应。使用定义的值时不会出现任何错误。当我将值更改为“ event”时,我得到了错误,但Lambda仍执行代码。
This code produces no error:
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'us-east-2', apiVersion: '2012-08-10'});
exports.handler = (event, context, callback) => {
const params = {
Item: {
"Clientid": {
S:"" + Math.floor(Math.random() * 400000 + 1)
},
"Age": {
N: "49"
},
"Height": {
N: "71"
},
"Income": {
N: "55000"
}
},
TableName: "compare-yourself"
};
dynamodb.putItem(params, function(err, data) {
if (err) {
console.log(err);
callback(err);
} else {
console.log(data);
callback(null, data);
}
});
This code produces the error but will still pass the data to Dynamo
};const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region: 'us-east-2', apiVersion: '2012-08-10'});
exports.handler = (event, context, callback) => {
const params = {
Item: {
"Clientid": {
S:"" + Math.floor(Math.random() * 400000 + 1)
},
"Age": {
N: event.age
},
"Height": {
N: event.height
},
"Income": {
N: event.income
}
},
TableName: "compare-yourself"
};
dynamodb.putItem(params, function(err, data) {
if (err) {
console.log(err);
callback(err);
} else {
console.log(data);
callback(null, data);
}
});
};
我正在尝试理解并消除错误。