-3

I have a lambda function which pushes data to s3. This is the function :

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?');
};

I need two modifications :

1) each and every time this lambda function is invoked, i want it to create a different file to push the data to it.

2) there is a folder "test1" inside bucket "test", I want to push the data inside test1 folder if test1 folder is available or else create test1 folder inside test bucket and push the data inside it.

Can you help me with this?

Thanks.

Asish
  • 409
  • 2
  • 4
  • 17

1 Answers1

0

I got a way out :) :)

How to create folder or key on s3 using AWS SDK for Node.js?

This one answers my problem.

Community
  • 1
  • 1
Asish
  • 409
  • 2
  • 4
  • 17