Skip to content

Instantly share code, notes, and snippets.

@mccabe615
Last active January 27, 2020 16:27
Show Gist options
  • Save mccabe615/b3458ba94168e68f4d0f9c35ac28caa9 to your computer and use it in GitHub Desktop.
Save mccabe615/b3458ba94168e68f4d0f9c35ac28caa9 to your computer and use it in GitHub Desktop.
Bash script to download the lambda code and delete it
#Script to delete lambdas after downloading the code
#Accepts a new line delimited file with lambda names or ARNs
#Usage: log into the AWS account on the command line
# delete-lambda.sh <filename>
while IFS="" read -r p || [ -n "$p" ];
do
if [ -z $1 ]; then
echo "Error: must supply a filename with line delimited values"
echo "Usage: delete-lambda.sh <filename>"
exit 1
fi
timestamp=$(date +%s)
printf '%s' "Downloading code for $p"
printf "\n\n";
aws lambda get-function --function-name "$p" --query 'Code.Location' |xargs wget -q -O "$p-$timestamp-code.zip"
printf '%s' "Deleting lambda: $p";
printf "\n\n";
if [ $? -eq 0 ]; then
aws lambda delete-function --function-name "$p"
else
echo "Code download failed, lambda not deleted"
fi
done < lambdas.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment