Created
May 25, 2018 07:38
-
-
Save vnpnlz/5e00ff52872b5147ca6a0928f9f51eaf to your computer and use it in GitHub Desktop.
Compressed and Upload Lambda Function Shell Script
This file contains 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
# Remove .pyc and _pycache_ | |
echo "Removing .pyc and __pycache__" | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
# Replace lambda handler based on your own use | |
HANDLER='handler' | |
find . | grep -E "(__pycache__|\.pyc|\.pyo|\.vscode$)" | xargs rm -rf | |
sleep 1 | |
# echo "${PWD##*/}.$HANDLER" | |
FILTER_STR_NAME=${PWD//-/_} | |
HANDLER_NAME="${FILTER_STR_NAME##*/}.$HANDLER" | |
zip -r "${PWD##*/}.zip" * | |
read -p "Create(c) or Update(u) Lambda Function? (c/u) " RESP | |
if [ "$RESP" = "c" ]; then | |
echo "Creating Lambda Function..." | |
aws lambda create-function \ | |
--region ap-southeast-2 \ | |
--function-name ${PWD##*/} \ | |
--zip-file fileb:////"$DIR/${PWD##*/}.zip"\ | |
--role arn:aws:iam::404728392173:role/serverless-publisher \ | |
--handler $HANDLER_NAME \ | |
--runtime python3.6 | |
else | |
echo "Updating Lambda Function..." | |
aws lambda update-function-code \ | |
--region ap-southeast-2 \ | |
--function-name ${PWD##*/} \ | |
--zip-file fileb:////"$DIR/${PWD##*/}.zip" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment