Last active
August 29, 2015 14:25
-
-
Save nikcorg/376e35614e1ff1087c8c to your computer and use it in GitHub Desktop.
Compile a self-contained bundle for use in AWS Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
ERR_BROWSERIFY_NOT_FOUND=1 | |
ERR_SOURCE_NOT_FOUND=2 | |
AWS_STDLIBS="aws-sdk dynamodb-doc" | |
err_exit() | |
{ | |
if [ "x$2" != "x" ]; then | |
echo "Error: $2" >&2 | |
fi | |
exit $1 | |
} | |
compile_omit_list() | |
{ | |
local IFS=" " | |
local OMIT_PARAMS | |
for LIB in $AWS_STDLIBS; do | |
OMIT_PARAMS="$OMIT_PARAMS -u $LIB" | |
done | |
echo $OMIT_PARAMS | |
} | |
if [ "x$(which browserify)" = "x" ]; then | |
err_exit $ERR_BROWSERIFY_NOT_FOUND "browserify not found" | |
fi | |
SOURCE="index.js" | |
if [ "x$1" != "x" ]; then | |
SOURCE="$1" | |
fi | |
if [ ! -f "$SOURCE" ]; then | |
err_exit $ERR_SOURCE_NOT_FOUND "source file not found: $SOURCE" | |
fi | |
TARGET="bundle-$SOURCE" | |
if [ "x$2" != "x" ]; then | |
TARGET="$2" | |
fi | |
browserify --bare --no-bf --standalone bundle $(compile_omit_list) -e "$SOURCE" > "$TARGET" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As long as not using native modules, this approach should work ok. For bundling with native modules, see: https://aws.amazon.com/blogs/compute/nodejs-packages-in-lambda/