LoginSignup
0
0

More than 5 years have passed since last update.

Windows+Node.js+gulp で AWS Lambda用zipファイルを作成したよ

Last updated at Posted at 2019-02-19

タイトルの通り、Windows環境のNode.jsでAWS Lambda用のZIPファイルを作成するタスクを書いたので、gulpfile.jsをさらしておくよ。

gulpfile.js
var gulp = require('gulp');
var zip = require('gulp-zip');
var install = require('gulp-install');
var tap = require('gulp-tap');
var rimraf = require('rimraf');
var mkdirp = require('mkdirp');

gulp.task('clean', (cb) => {
    rimraf('./dist', function(error){});
    cb();
});

gulp.task('init', (cb) => {
    mkdirp('./dist/build', function (err) {
            if (err) console.log(err);
    });
    cb();
});

gulp.task('modules', () => {
  return gulp.src("./package.json")
    .pipe(gulp.dest('./dist/build/'))
    .pipe(install({production: true}));
})

gulp.task('sources', () => {
  return gulp.src([
        './scripts/*.js'
        ],{base : './scripts'})
    .pipe(gulp.dest('./dist/build/'));
})

gulp.task('zip', () => {
  return gulp.src([
    './dist/build/**',
    ],{base : './dist/build'})
        .pipe(tap(function(file) {
            if (file.isDirectory()) {
                file.stat.mode = parseInt('40777', 8);
            }
        }))
        .pipe(zip('lambda-function.zip'))
        .pipe(gulp.dest('./dist'));
})

gulp.task('default', gulp.series('init', 'modules', 'sources', 'zip'));

これでgulp defaultを実行するとdistの下にlambda-function.zipというファイル名でZIPが作成される。実行に必要なnode_modulesを抱き込んでいるので、好きなライブラリが使えます。
あ、JavaScriptのソースファイルは全てscriptsというフォルダにまとめられているのが前提なので、利用する際は適宜書き換えて下さい。

肝は
* gulp 4対応
* Windows上でgulp-zipを使うとAWS Lambdaで実行出来ない問題に対応
と言ったところ。

それぞれの具体的な対応方法は各自で探してみて下さい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0