I am trying to copy files uploaded to an S3 bucket to create timestamped backups. (the 'live' file will overwritten periodically to maintain a perma-link)
AWScopyObject, however, does not seem to be executing. I am getting the following error
{
"errorMessage": "Process exited before completing request"
}
The code that causes this error is as follows;
console.log('Loading function');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
exports.handler = function(event, context) {
var srcBucket = event.Records[0].s3.bucket.name;
var srcKey = event.Records[0].s3.object.key;
var dstKey = srcBucket+'/backup/'+ Date.now() + '-' +srcKey;
console.log(srcKey);
console.log(dstKey);
var copyParams = {
Bucket: srcBucket,
CopySource : srcBucket + '/' + srcKey,
Key: dstKey
};
s3.copyObject(
copyParams,
function (err, data) {
if (err) {
console.log("ERROR copyObject");
console.log(err);
}
else {
console.log('SUCCESS copyObject');
}
context.done();
});
};
What could be causing lambda to exit before the AWSCopyObject callback? According to https://aws.amazon.com/blogs/compute/container-reuse-in-lambda/ this error suggests context.done() is never hit.
I was facing similar issue, seems issue i was getting only when i try to test using AWS Lambda console, But when i tried to execute test with real bucket(uploaded a test file) and Lambda function executed successfully.
Try to see 'Log output' you will get more detail about actual error which you are getting.
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With