Last active
June 2, 2022 12:21
-
-
Save stekern/ec53a6c329d108a6739fa8de84952569 to your computer and use it in GitHub Desktop.
Locate CloudFormation stacks created using CDK v1
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
#!/usr/bin/env bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
read -r -d '' -a regions < <(aws ec2 describe-regions --query "Regions[].[RegionName]" --output text && printf '\0') | |
for region in "${regions[@]}"; do | |
echo "[$region] Finding CloudFormation stacks deployed using CDK" | |
read -r -d '' -a stacks < <(aws cloudformation list-stacks --region "$region" --query "StackSummaries[?!contains(keys(@), 'DeletionTime')].[StackName]" --output text && printf '\0') | |
test -z "${stacks:-}" && continue | |
for stack in "${stacks[@]}"; do | |
template="$(aws cloudformation get-template --region "$region" --stack-name "$stack" --query "TemplateBody")" | |
if echo "$template" | grep "aws:cdk:path" > /dev/null; then | |
payload="$(echo "$template" | sed -n "s/^.*v2:deflate64:\([a-zA-Z0-9+=/]\{1,\}\).*$/\1/p")" | |
if [ -n "$payload" ]; then | |
decoded="$(echo "$payload" | base64 --decode | gunzip)" | |
echo " '$stack' is using CDK version $(echo "$decoded" | sed 's/^\([0-9.]\{1,\}\).*$/\1/')" | |
else | |
echo " '$stack' was deployed using CDK, but was unable to determine CDK version" | |
fi | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment