LAMBDA_FUNCTION_NAME=MyFunction
AWS_UPLOAD_CODE_PROFILE=MY_CLI_PROFILE
SLACK_DEV_NOTIFICATIONS_WEBHOOK_URL=https://hooks.slack.com/services/****/****/****
# Read the .env file
export $(egrep -v '^#' .env | xargs)
echo $LAMBDA_FUNCTION_NAME # Print function name
rm function.zip # Delete the old ZIP file from the last deploy
# Install all dependencies, in case we've missed something
npm install
# Build the ZIP file
zip -r function.zip \
app.js \
parseJotFormPayload.js \
node_modules \ # This is a directory with all our packages
package.json
echo "ℹ️ Built ZIP"
ls -lh function.zip # Print out the stats of the file, file size etc.
# Upload to AWS
echo "🌀 Uploading..."
aws lambda update-function-code \
--cli-connect-timeout 0 \ # Prevent upload from timing out if you have really slow Wi-Fi (cough, cough)
--function-name=$LAMBDA_FUNCTION_NAME \
--zip-file=fileb://function.zip \
--profile=$AWS_UPLOAD_CODE_PROFILE \
--region='us-east-1'
# Announce the new deploy in a Slack channel
curl -X POST -H 'Content-type: application/json' --data '{"text":"🚀 Lambda "'$LAMBDA_FUNCTION_NAME'" redeployed"}' $SLACK_DEV_NOTIFICATIONS_WEBHOOK_URL