2016-06-20 449 views
-3

我有一个将数据推送到s3的lambda函数。这是函数:从aws lambda上传到aws s3

var AWS = require('aws-sdk'); 
var s3 = new AWS.S3(); 

exports.handler = function(event, context) { 
    var s3 = new AWS.S3(); 
    var param = {Bucket: 'test', Key: 'testFile', Body: JSON.stringify(event)}; 
    console.log("EVENT DATA :" + param.Body); 
    s3.upload(param, function(err, data) { 
     if (err) console.log(err, err.stack); // an error occurred 
     else console.log(data);   // successful response 

     console.log('actually done!'); 
     context.done(); 
    }); 
console.log('done?'); 
}; 

我需要两个修改:

1)每本lambda函数被调用的时候,我想它来创建一个不同的文件将数据推到它。

2)bucket“test”内有一个文件夹“test1”,如果test1文件夹可用,我想推送test1文件夹内的数据,或者在test bucket内创建test1文件夹,并将其中的数据推送到其中。

你能帮我吗?

谢谢。

回答