Skip to content

Instantly share code, notes, and snippets.

@dsdenes
Last active February 17, 2016 10:46
Show Gist options
  • Save dsdenes/7480f34432784d071bfc to your computer and use it in GitHub Desktop.
Save dsdenes/7480f34432784d071bfc to your computer and use it in GitHub Desktop.
'use strict';
const q = require('q');
const globby = require('globby');
const path = require('path');
const fs = require('fs');
const AWS = require('aws-sdk');
const config = require('../../../config/aws');
const lambda = new AWS.Lambda(config.lambda.sdk);
module.exports = function() {
return function() {
const functionZipDirectories = globby.sync(path.join(config.lambda.functionsZipPath, '*.zip'));
const todo = functionZipDirectories.map(lambdaFunctionZipFile => {
const functionName = path.basename(lambdaFunctionZipFile, '.zip');
return uploadLambdaFunction(functionName);
});
return Promise.all(todo);
};
function uploadLambdaFunction(functionName) {
const zipFilePath = path.join(config.lambda.functionsZipPath, functionName + '.zip');
const functionFileZip = fs.readFileSync(zipFilePath);
var functionParams = {
FunctionName: functionName,
Publish: true,
ZipFile: functionFileZip
};
return q.nbind(lambda.updateFunctionCode, lambda)(functionParams).catch(err => {
throw err;
});
}
};
'use strict';
const config = require('../../../config/aws');
const zip = require('gulp-zip');
const globby = require('globby');
const path = require('path');
module.exports = function(gulp) {
return function() {
const functionDirectories = globby.sync(config.lambda.functionsPath);
const todo = functionDirectories.map(lambdaFunctionDirectory => {
const zipName = path.basename(lambdaFunctionDirectory) + '.zip';
return new Promise(resolve => {
gulp.src(path.join(lambdaFunctionDirectory, '**'))
.pipe(zip(zipName))
.pipe(gulp.dest(config.lambda.functionsZipPath))
.on('end', resolve);
});
});
return Promise.all(todo);
};
};
gulp.task('aws-lambda-upload', ['aws-lambda-zip'], localTasks.awsLambdaUpload);
gulp.task('aws-lambda-zip', ['aws-lambda-clean'], localTasks.awsLambdaZip);
gulp.task('aws-lambda-clean', localTasks.awsLambdaClean);
gulp.task('aws-lambda-update', ['aws-lambda-clean', 'aws-lambda-zip', 'aws-lambda-upload']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment