Last active
September 9, 2024 17:50
-
-
Save tobywf/6eb494f4b46cef367540074512161334 to your computer and use it in GitHub Desktop.
A quick script to remove old AWS Lambda function versions
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
from __future__ import absolute_import, print_function, unicode_literals | |
import boto3 | |
def clean_old_lambda_versions(): | |
client = boto3.client('lambda') | |
functions = client.list_functions()['Functions'] | |
for function in functions: | |
versions = client.list_versions_by_function(FunctionName=function['FunctionArn'])['Versions'] | |
for version in versions: | |
if version['Version'] != function['Version']: | |
arn = version['FunctionArn'] | |
print('delete_function(FunctionName={})'.format(arn)) | |
#client.delete_function(FunctionName=arn) # uncomment me once you've checked | |
if __name__ == '__main__': | |
clean_old_lambda_versions() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This Helped for my 88 lambda cleanup, thanks!