Wednesday, 12 April 2017

How to write Express module code in Lambda handler using Node js

The below code its working fine using express module.I need to implement same logic in Lambda using following Lambda Handler

exports.handler = function (event, context) {

------

}

using Express Module

var app = express();

var express = require('express');

app.get('/', function (req, res) {

downloadZipFile(params, downloadPath, function (err) {
    if (err) {
        res.status(500).send('Failed to download the file.');
    } else {
        processZipFile(downloadPath, function (err) {
            if (err) {
                res.status(500).send('Failed to process the file.');
            } else {
                res.send('File is downloaded');
            }
        });

    }

  });

});

function downloadZipFile(params, downloadPath, callback) {

const file = fs.createWriteStream(downloadPath);

s3.getObject(params)
.on('httpData', function (chunk) {
    file.write(chunk);
})
   .on('error', function (err) {

    callback(err);
})
.on('complete', function () {

    file.end();
})
 .send();
}

function processZipFile(filePath) 
{

//
}



via Sharan

No comments:

Post a Comment