deploy.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # "set -e" makes it so if any step fails, the script aborts:
  3. set -e
  4. cd "${BASH_SOURCE%/*}"
  5. source ./config.sh
  6. AwsRegion=$(aws configure get region)
  7. AwsAccountId=$(aws sts get-caller-identity --output text --query Account)
  8. # Build Lambda package
  9. rm -rf build
  10. mkdir build
  11. cd ..
  12. cp -r app.js config.js lib locales package-lock.json package.json public routes views aws/build
  13. cd aws/build
  14. cp ../src/* .
  15. npm install
  16. npm install aws-serverless-express
  17. cd ..
  18. # Replace variables (Region and AccountId) in API Swagger template
  19. cat api-swagger-template.json | sed -e "s/%Region%/${AwsRegion}/g" | sed -e "s/%AccountId%/${AwsAccountId}/g" | sed -e "s/%ApiTitle%/${StackName}/g"> api-swagger.json
  20. # Package SAM template (loads Lambda dist zips to S3 locations)
  21. aws cloudformation package \
  22. --template-file sam-template.json \
  23. --output-template-file sam-output.yml \
  24. --s3-bucket "${S3BucketArtifacts}" \
  25. --s3-prefix "${S3PrefixArtifacts}"
  26. # Deploy CloudFormation stack
  27. aws cloudformation deploy \
  28. --template-file sam-output.yml \
  29. --stack-name "${StackName}" \
  30. --capabilities CAPABILITY_IAM \
  31. --parameter-overrides \
  32. CommunityName="${CommunityName}" \
  33. SlackUrl="${SlackUrl}" \
  34. SlackToken="${SlackToken}" \
  35. InviteToken="${InviteToken}" \
  36. RecaptchaSiteKey="${RecaptchaSiteKey}" \
  37. RecaptchaSecretKey="${RecaptchaSecretKey}" \
  38. Locale="${Locale}"
  39. Url=$(aws cloudformation describe-stacks --stack-name ${StackName} | grep OutputValue | cut -f 4 -d'"')
  40. echo
  41. echo 'Deployed Slack Inviter!'
  42. echo
  43. echo "Account Id: ${AwsAccountId}"
  44. echo " Region: ${AwsRegion}"
  45. echo "Stack Name: ${StackName}"
  46. echo " URL: ${Url}"