Let\'s say that I have a machine that I want to be able to write to a certain log file stored on an S3 bucket.
So, the machine needs to have writing abilities to tha
I had the similar issue and this is what I had asked
how to Append data in file using AWS Lambda
Here's What I come up with to solve the above problem:
Use getObject to retrive from the existing file
s3.getObject(getParams, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else{
console.log(data); // successful response
var s3Projects = JSON.parse(data.Body);
console.log('s3 data==>', s3Projects);
if(s3Projects.length > 0) {
projects = s3Projects;
}
}
projects.push(event);
writeToS3(); // Calling function to append the data
});
Write function to append in the file
function writeToS3() {
var putParams = {
Body: JSON.stringify(projects),
Bucket: bucketPath,
Key: "projects.json",
ACL: "public-read"
};
s3.putObject(putParams, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
callback(null, 'Hello from Lambda');
});
}
Hope this help!!