Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brunolemos
Last active December 7, 2022 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunolemos/7165c1533266a9b83dd9f06ca413c208 to your computer and use it in GitHub Desktop.
Save brunolemos/7165c1533266a9b83dd9f06ca413c208 to your computer and use it in GitHub Desktop.
Delete all AWS Lambdas (old versions) except $LATEST
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