Skip to content

Instantly share code, notes, and snippets.

@bahrmichael
Created October 2, 2020 09:49
Show Gist options
  • Save bahrmichael/105d8dae2b54e27ac6565d849d2f749b to your computer and use it in GitHub Desktop.
Save bahrmichael/105d8dae2b54e27ac6565d849d2f749b to your computer and use it in GitHub Desktop.
# tested with aws cli v1 and a webpack build
# this is the relative path to the folder that contains your build assets
BUILD_FOLDER=build
# you can improve upload speed by naming the files explicitely instead of all (.)
(cd $BUILD_FOLDER && zip bundle.zip .)
export AWS_PROFILE="${AWS_PROFILE:-default}"
echo "Using AWS Profile: $AWS_PROFILE"
# the following section tries to discover the function name. if you set an explicit one via FUNCTION_NAME, this section will be skipped.
if [[ -z "$FUNCTION_NAME" ]]; then
if [[ -z "$FUNCTION_PREFIX" ]]; then
echo "Please specify a FUNCTION_PREFIX or full FUNCTION_NAME!"
exit 1
fi
FUNCTION_NAME=`aws lambda list-functions | grep -E -o "\"$FUNCTION_PREFIX.*\"" | tr -d '"'`
echo "Discovered function name: $FUNCTION_NAME"
else
echo "Using FUNCTION_NAME env var: $FUNCTION_NAME"
fi
# this is a manual check to confirm that the right function goes to the right account
read "continue?Are you sure that you want to deploy $FUNCTION_NAME to AWS_PROFILE $AWS_PROFILE? (y/N) "
if [[ "$continue" != 'y' ]]; then
exit 0
fi
start=`date +%s`
aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://$BUILD_FOLDER/bundle.zip --publish
end=`date +%s`
runtime=$((end-start))
echo "Deployed in $runtime seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment