Created
December 29, 2018 18:36
-
-
Save joshspicer/c98c6d7f2728cf787f1432de92088bf8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# Builds, zips, and uploads server code to AWS Lambda | |
# Place in root folder at SAME LEVEL as `/server` | |
# aws-cli must be configured. Will use default aws account. | |
ZIPNAME=<ANY NAME> | |
REGION=<YOUR REGION> | |
if [ "$#" -ne 1 ]; then | |
echo "[-] Usage: ./deploy-server-to-lambda <prod|staging>" | |
exit 1 | |
fi | |
case $1 in | |
'prod' ) | |
FUNCTIONNAME='prod-server' ;; # This name must exactly match the lambda func you created above. | |
'staging' ) | |
FUNCTIONNAME='staging-server' ;; * ) | |
echo "[-] Usage: ./deploy-server-to-lambda <prod|staging>" | |
exit 1 | |
;; | |
esac | |
read -p "[+] Deploying to <$FUNCTIONNAME>. Are you sure? (Y) " -n 1 -r | |
echo | |
if [[$REPLY =~ ^[Yy]$]] | |
then | |
echo "===== Running Lambda Deploy =====" | |
rm $ZIPNAME | |
rm -r dist/ | |
yarn build &> /dev/null | |
echo "[+] Zipping Lambda Build..." | |
zip -r $ZIPNAME . -x "./server/*" &> /dev/null | |
rm -r dist/ | |
echo "[+] Uploading to Lambda..." | |
aws lambda update-function-code --function-name $FUNCTIONNAME --zip-file fileb://./$ZIPNAME --region $REGION | grep "LastModified" | sed -e 's/^[ \t]*//' | |
echo "[+] Upload Complete." | |
rm $ZIPNAME | |
echo "[+] Cleanup Complete." | |
echo "===== Finished Lambda Deploy =====" | |
else | |
echo "[-] Lambda Deploy Canceled" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment