delete-stack.sh 891 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. set -e
  3. source common.sh
  4. if [ -z "$1" ]; then
  5. echo "ERROR: Configuration file not passed"
  6. echo "Please use ./delete-stack.sh PATH/TO/CONFIG to run this script"
  7. exit 1
  8. else
  9. echo "Using $1 file for config"
  10. source $1
  11. fi
  12. BUCKET_NAME=$(get_aws_export $NEW_STACK_NAME "S3BucketName")
  13. # Delete the CloudFormation stack
  14. echo -e "\n\n=========== Emptying bucket $BUCKET_NAME ==========="
  15. aws s3 rm s3://$BUCKET_NAME --recursive --profile $CLI_PROFILE || echo "No bucket"
  16. echo -e "\n\n=========== Deleting stack $NEW_STACK_NAME ==========="
  17. aws cloudformation delete-stack --stack-name $NEW_STACK_NAME --profile $CLI_PROFILE
  18. echo -e "\n\n=========== Waiting for stack deletion to complete ==========="
  19. aws cloudformation wait stack-delete-complete --stack-name $NEW_STACK_NAME --profile $CLI_PROFILE
  20. echo -e "\n\n=========== Stack $NEW_STACK_NAME deleted ==========="