We are working on a project/framework that aids in deploying and maintaining code in AWS Lambda. I want to build/bundle all node.js code for a lambda function into one js file b
I prefer not to use single file solution, but to upload zip file with all my code packed. I use gulp for this. The code below only uploads production dependencies, excluding development ones and zip archive from previous upload. You may also exclude your test folder or any other file using parameters of gulp.src
.
Just to mention, aws-sdk
library is in my development dependencies as AWS Lambda already has a copy ;)
var gulp = require('gulp');
var lambda = require('gulp-awslambda');
var zip = require('gulp-zip');
var settings = require('./settings');
var argv = require('yargs').argv;
var p = require('./package.json');
gulp.task('default', function () {
var profile = argv.profile;
var src = ['**', '!*.zip', '!node_modules/aws-sdk{,/**}'];
var i;
for (i in p.devDependencies) {
src.push("!node_modules/" + i + "{,/**}");
}
if (!profile) {
profile = settings.aws.defaultProfile;
}
return gulp.src(src)
.pipe(zip('archive.zip'))
.pipe(lambda(settings.aws.lambda, {
region: settings.aws.region,
profile: profile
}))
.pipe(gulp.dest('.'));
});