Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ a callback function. These will still work for now for backward compatibility,

v0.10.36 is still supported, and can be targeted by changing the `AWS_RUNTIME` value to `nodejs` in the `.env` file.

## Post install script
When running `node-lambda deploy` if you need to do some action after `npm install --production` and before deploying to AWS Lambda (i.e. replace some modules with precompiled ones or download some libraries) you can create `post_install.sh` script. If the file exists the script will be executed (and output shown after execution) if not it is skipped. Make sure that the script is executable.

## Other AWS Lambda Tools Projects

Expand Down
48 changes: 40 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,32 @@ Lambda.prototype._npmInstall = function (program, codeDirectory, callback) {
});
};

Lambda.prototype._postInstallScript = function (codeDirectory, callback) {
var script_filename = 'post_install.sh';
var cmd = './'+script_filename;

var filePath = [codeDirectory, script_filename].join('/');

fs.exists(filePath, function(exists) {
if (exists) {
console.log('=> Running post install script '+script_filename);
exec(cmd, { cwd: codeDirectory,maxBuffer: 50 * 1024 * 1024 }, function(error, stdout, stderr){

if (error) callback(error +" stdout: " + stdout + "stderr"+stderr);
else {
console.log("\t\t"+stdout);
callback(null);
}
});


} else {
callback(null);
}
});

};

Lambda.prototype._zip = function (program, codeDirectory, callback) {

var options = {
Expand Down Expand Up @@ -295,16 +321,22 @@ Lambda.prototype._archive = function (program, archive_callback) {
return archive_callback(err);
}

// Add custom environment variables if program.configFile is defined
if (program.configFile) {
_this._setEnvironmentVars(program, codeDirectory);
}
console.log('=> Zipping deployment package');
_this._postInstallScript(codeDirectory, function (err) {
if (err) {
return archive_callback(err);
}

// Add custom environment variables if program.configFile is defined
if (program.configFile) {
_this._setEnvironmentVars(program, codeDirectory);
}
console.log('=> Zipping deployment package');

var archive = process.platform !== 'win32' ? _this._nativeZip : _this._zip;
archive = archive.bind(_this);
var archive = process.platform !== 'win32' ? _this._nativeZip : _this._zip;
archive = archive.bind(_this);

archive(program, codeDirectory, archive_callback);
archive(program, codeDirectory, archive_callback);
});
});
});
};
Expand Down