【发布时间】:2016-01-07 10:59:02
【问题描述】:
我既不是 Node.js 也不是 AWS Lambda 专家,所以我可能会做错事。 我编写了下面的代码,当使用 AWS CLI 从命令行执行时运行良好,但根本不会在 lambda 函数中调用。
你能告诉我要寻找什么或调试它以了解原因吗? 谢谢。
var aws = require('aws-sdk');
console.log('Loading function');
exports.handler = function(event, context) {
console.log('Received event:', JSON.stringify(event, null, 2));
console.log('value1 =', event.key1);
var params = {
Bucket: 'nicobucket1',
Body: 'hellolll',
Key: 'mykey',
};
var s3 = new aws.S3();
console.log('Created S3 object, invoking upload...' + JSON.stringify(s3));
s3.upload(params, function(err, data){
console.log('...in function upload...');
if(err){
console.log(err);
context.fail('Could not create object in bucket...');
}
else console.log ('Uploaded data, check the console...');
});
context.succeed('Created object in S3 bucket!');
};
我在日志中看到除了 s3.upload 函数中的所有 console.log 消息。当然,不会创建对象。 从命令行一切都很好。
【问题讨论】:
标签: lambda