Last active
March 12, 2019 14:10
-
-
Save angelodlfrtr/cf55339ff456e961ff79b6936038856d 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 | |
| set -e | |
| # Test argument existence | |
| if [ -z "$1" ] | |
| then | |
| echo ">> Function path must be supplied" | |
| exit 1 | |
| fi | |
| # Test path existence | |
| if [ ! -d "$1" ] | |
| then | |
| echo ">> Path supplied does not exist" | |
| exit 1 | |
| fi | |
| # Test package.json existence | |
| if [ ! -f "$1/package.json" ] | |
| then | |
| echo ">> package.json does not exist" | |
| exit 1 | |
| fi | |
| # Get func infos | |
| funcName=$(cat $1/package.json | jq -r '.name') | |
| funcRegion=$(cat $1/package.json | jq -r '.region') | |
| if [ "$funcName" == "null" ] | |
| then | |
| echo ">> name entry in package.json is missing" | |
| exit 1 | |
| fi | |
| if [ "$funcRegion" == "null" ] | |
| then | |
| echo ">> region entry in package.json is missing" | |
| exit 1 | |
| fi | |
| read -p ">> Do you want really to push function $funcName in region $funcRegion ? [Yy]" -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]] | |
| then | |
| if [[ $2 != "--no-clean" ]]; then | |
| # Reinstall node packages | |
| cd $1 | |
| rm -Rf ./node_modules | |
| yarn install | |
| # Clean node_modules | |
| yarn autoclean --init | |
| yarn autoclean --force | |
| fi | |
| # Zip folder | |
| fileName=$(uuidgen)".zip" | |
| zipPath="/tmp/$fileName" | |
| cd $1 | |
| echo ">> Creating zip file ..." | |
| zip -rq $zipPath ./* | |
| # Push function to AWS | |
| echo ">> Push function to aws ..." | |
| currentRegion=$(aws configure get region) | |
| # Set function region | |
| echo ">> Use region $funcRegion" | |
| aws configure set region $funcRegion | |
| echo ">> Upload function to s3" | |
| aws s3 cp $zipPath s3://s3-functions/ | |
| echo ">> Update function code ..." | |
| aws lambda update-function-code --function-name $funcName --s3-bucket "s3-functions" --s3-key $fileName | |
| # Bash to initial region | |
| echo ">> Bask to region $currentRegion" | |
| aws configure set region $currentRegion | |
| echo ">> Delete zip file $zipPath" | |
| echo ">> All done" | |
| # Display notification | |
| noti | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment