Skip to content

Instantly share code, notes, and snippets.

@dvonlehman
Last active January 19, 2016 00:17
Show Gist options
  • Save dvonlehman/2386826351e85fb96163 to your computer and use it in GitHub Desktop.
Save dvonlehman/2386826351e85fb96163 to your computer and use it in GitHub Desktop.
lambda deploy gulpfile
var gulp = require('gulp');
var zip = require('gulp-zip');
var del = require('del');
var install = require('gulp-install');
var runSequence = require('run-sequence');
var awsLambda = require("node-aws-lambda");
gulp.task('clean', function(cb) {
del(['./dist', './dist.zip'], cb);
});
gulp.task('copy', function() {
return gulp.src('index.js')
.pipe(gulp.dest('dist/'));
});
gulp.task('node-mods', function() {
return gulp.src('./package.json')
.pipe(gulp.dest('dist/'))
.pipe(install({production: true}));
});
// Clean up all aws-sdk directories from node_modules. We don't
// need to upload them since the Lambda instance will already
// have it available globally.
gulp.task('clean-aws-sdk', function(callback) {
del(['dist/node_modules/**/aws-sdk'], callback);
});
gulp.task('zip', function() {
// Don't need the package.json since all deps are included in zip file
return gulp.src(['dist/**/*', '!dist/package.json'])
.pipe(zip('dist.zip'))
.pipe(gulp.dest('./'));
});
gulp.task('upload', function(callback) {
awsLambda.deploy('./dist.zip', {
region: 'us-west-2', // or your AWS region
handler: 'index.handler',
role: '', // the arn of the IAM role to run the function as
functionName: '' // Lambda function name,
timeout: 10 // can be up to 300 seconds
}, callback);
});
gulp.task('deploy', function(callback) {
return runSequence(
['clean'],
['copy'],
['node-mods'],
['clean-aws-sdk'],
['zip'],
['upload'],
callback
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment