delete-stack.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. set -e
  3. if [ -z "$1" ]; then
  4. echo "ERROR: Configuration file not passed"
  5. echo "Please use ./delete-stack.sh PATH/TO/CONFIG to run this script"
  6. exit 1
  7. else
  8. echo "Using $1 file for config"
  9. source $1
  10. fi
  11. get_aws_export () {
  12. RESULT=$(aws cloudformation list-exports \
  13. --profile $CLI_PROFILE \
  14. --query "Exports[?starts_with(Name,'${NEW_STACK_NAME}$1')].Value" \
  15. --output text | sed 's/\t\t*/\n/g')
  16. echo -e $RESULT | tr " " "\n"
  17. }
  18. BUCKET_NAME=$(get_aws_export "S3BucketName")
  19. # Delete the CloudFormation stack
  20. echo -e "\n\n=========== Emptying bucket $BUCKET_NAME ==========="
  21. aws s3 rm s3://$BUCKET_NAME --recursive --profile $CLI_PROFILE || echo "No bucket"
  22. echo -e "\n\n=========== Deleting stack $NEW_STACK_NAME ==========="
  23. aws cloudformation delete-stack --stack-name $NEW_STACK_NAME --profile $CLI_PROFILE
  24. echo -e "\n\n=========== Waiting for stack deletion to complete ==========="
  25. aws cloudformation wait stack-delete-complete --stack-name $NEW_STACK_NAME --profile $CLI_PROFILE
  26. echo -e "\n\n=========== Stack $NEW_STACK_NAME deleted ==========="