Guest User

Untitled

a guest
Nov 22nd, 2017
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #title : lambda-publish-gradle.sh
  3. #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!
  4. #author : Christian-André Giehl <christian@emailbrief.de>
  5. #date : 20170410
  6. #version : 1.1
  7. #usage : sh lambda-publish-gradle.sh
  8. #==============================================================================
  9.  
  10. # Exits in case the supplied state is != 0. State is typically supplied via $?
  11. exitOnError() {
  12. state=$1
  13. msg=$2
  14. if [ $state -ne 0 ]; then
  15. echo "!!! ${msg}"
  16. echo "### Exiting."
  17. exit $state
  18. fi
  19. }
  20.  
  21. # Check is AWS CLI is there
  22. command -v aws
  23. exitOnError $? "AWS CLI not found or not accessible!"
  24.  
  25. #
  26. # AWS cfg
  27. #
  28. ARN=arn:aws:lambda:eu-central-1:216518302536:function:lambda-formatcheck
  29. PROFILE=internal-user # make sure profile exists in ~/.aws/config
  30. REGION=eu-central-1
  31.  
  32. echo "### Starting gradle..."
  33. ./gradlew clean test fatJar
  34. exitOnError $? "Unable to build!"
  35. JAR=$(find ./ -iname *.jar -print -quit)
  36.  
  37. echo "### Using file '${JAR}' to deploy to lambda..."
  38.  
  39. read -p "-----> DO YOU REALLY WANT TO DEPLOY? [Yy]es " -n 1 -r
  40. if ! [[ $REPLY =~ ^[Yy]$ ]]
  41. then
  42. echo "!!! ABORTED !!!"
  43. exit 1
  44. fi
  45.  
  46. #
  47. # Deploy!
  48. #
  49. aws --profile ${PROFILE} \
  50. --region ${REGION} \
  51. lambda update-function-code \
  52. --function-name ${ARN} \
  53. --zip-file fileb://${JAR} \
  54. --publish
  55. exitOnError $? "Deployment failed!"
  56.  
  57. echo "### Done!"
Add Comment
Please, Sign In to add comment