Last active
October 13, 2020 11:56
-
-
Save Hritik14/e504fc4d02a7d8d8032f026c93edafe9 to your computer and use it in GitHub Desktop.
Deploy go project to AWS lambda.
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
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
#CHANGE THIS | |
AWS_FUNCTION_NAME=routine | |
_green(){ | |
echo -e "\033[32m$1\033[0m" | |
} | |
_red(){ | |
echo -e "\033[31m$1\033[0m" | |
} | |
cleanup(){ | |
rm -f "$ZIP" | |
} | |
trap cleanup SIGINT EXIT | |
_green "[+] aws function name: $AWS_FUNCTION_NAME" | |
MODULE=$(go mod graph | head -n1 | cut -f 1 -d " ") | |
_green "[+] Detected module name: $MODULE" | |
_green "[+] Building" | |
go clean | |
CGO_ENABLED=0 go build | |
_green "[+] Zipping" | |
ZIP=$(mktemp "lambda-$AWS_FUNCTION_NAME-XXX.zip") | |
zip --display-globaldots - "$MODULE" > "$ZIP" | |
_green "[+] Deploying" | |
reply=$(aws lambda update-function-code \ | |
--function-name "$AWS_FUNCTION_NAME" \ | |
--zip-file "fileb://$ZIP" ) | |
echo "$reply" | jq '{Handler,State,LastModified,CodeSize,LastUpdateStatus}' | tr -d "{},\"" | |
if [[ $(echo "$reply" | jq '.LastUpdateStatus') == "\"Successful\"" ]]; then | |
_green "[+] Done" | |
else | |
_red "[-] Failed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment