Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. deploy-lambda $1
  4.  
  5. # A little shell script I worked up to deploy Lambda functions from my local dev box
  6. function deploy-lambda {
  7. basedir=$HOME/work
  8. dir=$1
  9. role=${LAMBDA_ROLE:-arn:aws:iam::123456789012:role/default-role-goes-here}
  10. runtime=${LAMBDA_RUNTIME:-provided}
  11.  
  12. if [ ! $dir ] ; then
  13. if [[ ! $PWD =~ $HOME/work/ ]] ; then
  14. echo "You must call package_lambda from a directory under $HOME/work or with an argument"
  15. return 1;
  16. fi
  17. dir=$PWD;
  18. else
  19. dir="$basedir/$dir"
  20. fi
  21.  
  22. if [ ! -d $dir ] ; then
  23. echo "No such directory \"$dir\""
  24. return 1;
  25. fi
  26.  
  27. function_name=${FUNCTION_NAME:-`basename $dir`}
  28. function_exists=`aws lambda get-function --function-name $function_name 2> /dev/null`
  29. if [ ! "$function_exists" ] ; then
  30. echo "Creating Lambda function $function_name"
  31. # I'm using this to do Lambda functions in Perl, which require a custom runtime. Take out the two lines below
  32. # if you don't need custom layers
  33. layer_name=my_custom_runtime
  34. layer=${LAMBDA_LAYER:-`aws lambda list-layer-versions --layer-name $layer_name --region us-east-1 --query 'LayerVersions[0].LayerVersionArn'`}
  35.  
  36. awscmd="aws lambda create-function --function-name $function_name --handler handler.handle \
  37. --role $LAMBDA_ROLE --runtime provided --layers $layer --zip-file fileb://$basedir/$function_name.zip"
  38. else
  39. echo "Updating Lambda function $function_name"
  40. awscmd="aws lambda update-function-code --function-name $function_name --zip-file fileb://$basedir/$function_name.zip"
  41. fi
  42.  
  43. # OK, this is still pretty perl specific. I'll fix that later maybe
  44. zipcmd="zip -r $basedir/$function_name.zip handler.pl local"
  45. cd $dir
  46. echo "$zipcmd && $awscmd"
  47. if sh -c "$zipcmd && $awscmd" ; then
  48. rv=0
  49. else
  50. rv=-1
  51. fi
  52. cd $OLDPWD
  53. return $rv
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement