-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathclean_old_lambda.py
More file actions
30 lines (26 loc) · 1.25 KB
/
clean_old_lambda.py
File metadata and controls
30 lines (26 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import absolute_import, print_function, unicode_literals
import boto3
def clean_old_lambda_versions(marker = ''):
client = boto3.client('lambda')
if marker == '':
functions = client.list_functions()
else:
functions = client.list_functions(Marker=marker)
for function in functions['Functions']:
#if function['FunctionName'] != "lamda-at-edge-name": #uncomment and replace lamda-at-edge-name with your lambda at edge to ignore lambda at edge
while True:
versions = client.list_versions_by_function(FunctionName=function['FunctionArn'])['Versions']
if len(versions) == 1:
print('{}: done'.format(function['FunctionName']))
break
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
#else : #uncomment in-accordance with above if
# print('Not lambda')
if 'NextMarker' in functions:
clean_old_lambda_versions(functions['NextMarker'])
if __name__ == '__main__':
clean_old_lambda_versions()