Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda copyObject "Process exited before completing request"

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.

like image 826
user3737396 Avatar asked May 21 '15 14:05

user3737396


1 Answers

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

like image 141
Suresh Avatar answered Oct 16 '22 07:10

Suresh