Last active
December 7, 2022 02:17
-
-
Save brunolemos/7165c1533266a9b83dd9f06ca413c208 to your computer and use it in GitHub Desktop.
Delete all AWS Lambdas (old versions) except $LATEST
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
lambda_functions=$(aws lambda list-functions | jq -r '.Functions' | jq -c '.[]') | |
for function in $lambda_functions | |
do | |
function_name=$(echo $function | jq -r '.FunctionName') | |
current_version=$(echo $function | jq -r '.Version') | |
lambda_versions=$(aws lambda list-versions-by-function --function-name $function_name | jq -r '.Versions' | jq -c '.[]') | |
for version in $lambda_versions | |
do | |
arn=$(echo $version | jq -r '.FunctionArn') | |
version_number=$(echo $version | jq -r '.Version') | |
if [ "$current_version" == "$version_number" ]; then | |
echo "Skip $arn" | |
continue | |
else | |
echo "Delete $arn" | |
fi | |
aws lambda delete-function --function-name $arn --qualifier $version_number | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment