Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- #title : lambda-publish-gradle.sh
- #description : For gradle projects! Convenience script to build, pack and upload code to an AWS Lambda function, using the AWS CLI. For personal and experimental use only!
- #author : Christian-André Giehl <christian@emailbrief.de>
- #date : 20170410
- #version : 1.1
- #usage : sh lambda-publish-gradle.sh
- #==============================================================================
- # Exits in case the supplied state is != 0. State is typically supplied via $?
- exitOnError() {
- state=$1
- msg=$2
- if [ $state -ne 0 ]; then
- echo "!!! ${msg}"
- echo "### Exiting."
- exit $state
- fi
- }
- # Check is AWS CLI is there
- command -v aws
- exitOnError $? "AWS CLI not found or not accessible!"
- #
- # AWS cfg
- #
- ARN=arn:aws:lambda:eu-central-1:216518302536:function:lambda-formatcheck
- PROFILE=internal-user # make sure profile exists in ~/.aws/config
- REGION=eu-central-1
- echo "### Starting gradle..."
- ./gradlew clean test fatJar
- exitOnError $? "Unable to build!"
- JAR=$(find ./ -iname *.jar -print -quit)
- echo "### Using file '${JAR}' to deploy to lambda..."
- read -p "-----> DO YOU REALLY WANT TO DEPLOY? [Yy]es " -n 1 -r
- if ! [[ $REPLY =~ ^[Yy]$ ]]
- then
- echo "!!! ABORTED !!!"
- exit 1
- fi
- #
- # Deploy!
- #
- aws --profile ${PROFILE} \
- --region ${REGION} \
- lambda update-function-code \
- --function-name ${ARN} \
- --zip-file fileb://${JAR} \
- --publish
- exitOnError $? "Deployment failed!"
- echo "### Done!"
Add Comment
Please, Sign In to add comment