Skip to content

Instantly share code, notes, and snippets.

@joshspicer
Created December 29, 2018 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshspicer/c98c6d7f2728cf787f1432de92088bf8 to your computer and use it in GitHub Desktop.
Save joshspicer/c98c6d7f2728cf787f1432de92088bf8 to your computer and use it in GitHub Desktop.
#!/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