5
votes

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.

1
Perhaps the copyObject is taking longer than expected? What's the time limit on the lambda? When you run the code from your dev environment, how long does it take to execute? - Max
Did you get it resolved? I have similar case, going to try java - st78
@st78 Did you ever resolve this issue on your end? I'm having the same issue. - Stephen Tetreault

1 Answers

5
votes

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