Skip to content

Instantly share code, notes, and snippets.

@jakekara
Last active July 5, 2022 16:27
Show Gist options
  • Save jakekara/56f37e0542ac63d0e1370c3ccd5ddd43 to your computer and use it in GitHub Desktop.
Save jakekara/56f37e0542ac63d0e1370c3ccd5ddd43 to your computer and use it in GitHub Desktop.
Generate delete commands for old versions of lambdas
# Generate a bunch of commands to delete all versions of
# lambdas with a given LAMBA_PREFIX
#
# this script generates `delete-commands.sh` which you can
# inspect first before running. this is super dangerous so
# you probably should not use this script.
LAMBDA_PREFIX=example-lambda-group-name
for FUNCTION in $(aws lambda list-functions --region=us-east-1 \
| jq -r '.Functions[].FunctionName' \
| grep $LAMBDA_PREFIX)
do
echo
echo \# ------------------------
echo \# $FUNCTION
echo \# ------------------------
echo
for VERSION in $(aws lambda list-versions-by-function \
--function-name=$FUNCTION \
--region=us-east-1 \
| jq -r '.Versions[].FunctionArn')
do
if [[ "$VERSION" == *LATEST ]]
then
echo \# skipping $VERSION
continue
fi
echo aws lambda delete-function --region=us-east-1 \
--function-name $VERSION
done
done > delete-commands.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment