0

I am new to AWS Lambda. I got a working model of lambda function which logs the json data to cloudwatch and also S3 bucket.

This is the function :

exports.handler = function(event, context) {
    var s3 = new AWS.S3();
    var param = {Bucket: 'test', Key: 'test123', Body: event.name};
    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?');
};

This is my json data :

{
  "name": "XYZ ABC",
  "value": 123
}

How should I push the whole JSON data given above to S3 and CloudFront logs rather than just event.name?

Thanks.

1 Answer 1

2

Change event.name to JSON.stringify(event). If you get [object Object] somewhere, change it to JSON.stringify(event, null, 2)

Sign up to request clarification or add additional context in comments.

1 Comment

I tried that earlier. It does not work. EVENT DATA :[object Object] gets logged and i get exception while uploading the data to S3. Exception is [Error: Unsupported body payload object] 'Error: Unsupported body payload object\n at ManagedUpload.self.fillQueue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.