Skip to content

Instantly share code, notes, and snippets.

@jed
Created August 28, 2015 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jed/72fd006b9c800c66c3fd to your computer and use it in GitHub Desktop.
Save jed/72fd006b9c800c66c3fd to your computer and use it in GitHub Desktop.
Using iojs on AWS Lambda
import {join} from "path"
import browserify from "browserify"
import babelify from "babelify"
import archiver from "archiver"
let opts = {
standalone: "code",
// these are the API equivalent of --node
// https://github.com/substack/node-browserify/blob/master/bin/args.js#L67-L78
bare: true,
browserField: false,
builtins: false,
commondir: false,
detectGlobals: false,
igv: "__filename,__dirname"
}
let handlerPath = join(__dirname, process.argv[2])
let indexPath = join(__dirname, "index.js")
let iojsPath = join(__dirname, "vendor", "iojs")
let iojs = createReadStream(iojsPath)
let handler = browserify(handlerPath, opts)
.transform(babelify)
.exclude("aws-sdk")
.bundle()
let index = browserify(indexPath, opts)
.transform(babelify)
.exclude("aws-sdk")
.bundle()
let zip = archiver("zip")
.append(iojs, {name: "iojs", mode: 0o755})
.append(handler, {name: "handler.js"})
.append(index, {name: "index.js"})
.finalize()
zip.pipe(process.stdout)
$ babel-node bundle.js my-lambda.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment