Skip to content

Instantly share code, notes, and snippets.

@jed jed/bundle.js
Created Aug 28, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.