Created
January 31, 2017 04:54
-
-
Save willgarcia/17bfece2b1470f3e85253a645bb1be30 to your computer and use it in GitHub Desktop.
Delete all AWS resources (lambdas, cloudfront distribs, ec2, lb, api-gateways, ...)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
AWS_FUNCTIONS=$(aws lambda list-functions --query "Functions[].FunctionArn") | |
for func in $AWS_FUNCTIONS | |
do | |
CMD="aws lambda delete-function --function-name $func" | |
echo $CMD | |
$CMD | |
done | |
echo "-- Lambda functions deleted" | |
AWS_CLOUDFRONT_DISTRIBS=$(aws cloudfront list-distributions --query DistributionList.Items[].Id) | |
for elem in $AWS_CLOUDFRONT_DISTRIBS | |
do | |
aws cloudfront get-distribution-config --id $elem --output json > distrib-config.json | |
ETAG=$(aws cloudfront get-distribution-config --id E2ZPP4ZMA4Z76V --output json | jq .ETag) | |
cat distrib-config.json | jq ".DistributionConfig.Enabled = false" | jq .DistributionConfig > distrib-config-disabled.json | |
CMD="aws cloudfront update-distribution --id $elem --distribution-config file://distrib-config-disabled.json --if-match $ETAG" | |
echo $CMD | |
$CMD | |
STATUS=$(aws cloudfront get-distribution --id E2ZPP4ZMA4Z76V --output json | jq .Distribution.Status) | |
while [ $STATUS = '"InProgress"' ] | |
do | |
sleep 10 | |
echo "-- Waiting for the distribution to be disabled" | |
done | |
CMD="aws cloudfront delete-distribution --id $elem --if-match $ETAG" | |
echo $CMD | |
$CMD | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment