I put my code into different modules:
.....
var util = require('util');
var s3 = new AWS.S3();
exports.perform_flatten = function(event, context) {
     .......
     CONTEXT = context;
   s3_helper.get_object(SRC_BUCKET, SRC_KEY, this.flatten);
};
this.flatten is a callback to a module in the same file
exports.flatten = function(data){
    .......
 s3.putObject({Bucket: dst_bucket, Key: dst_key, Body: buffer}, function(err, data) {
    if (err){
      console.log(err, err.stack); // an error occurred
    }else{
      console.log(data);           // successful response
      CONTEXT.done();
    }
  });
}
The code runs perfectly until it comes to this line CONTEXT.done();.
Then I get the error: undefined is not a function
I do not understand why? Especially because I believe I declared CONTEXT as global right?
I have to call context.done() in order to execute a Lambda function on Amazon. http://docs.aws.amazon.com/lambda/latest/dg/programming-model.html THANKS