Skip to content

Commit dc40f0d

Browse files
committed
fixup! Delete inactive function versions at deploy time (#5927)
1 parent 72000ec commit dc40f0d

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

scripts/delete_older_function_versions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Delete all published versions of the AWS Lambda function except for the version specified to keep.
2+
Delete all versions of a Lambda function prior to the specified one.
33
"""
44
import argparse
55
import logging
@@ -32,6 +32,7 @@ def main(argv: list[str]):
3232
required=True,
3333
help='The name of the Lambda function')
3434
parser.add_argument('--function-version', '-v',
35+
type=int,
3536
required=True,
3637
help='The Lambda function version to keep')
3738
args = parser.parse_args(argv)

src/azul/lambdas.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ def list_lambdas(self) -> list[Lambda]:
116116

117117
def delete_older_function_versions(self,
118118
function_name: str,
119-
keep_version: str) -> None:
119+
keep_version: int) -> None:
120120
"""
121121
Delete all versions of a Lambda function prior to the specified one.
122-
Raises an error if the specified version does not exist.
123122
124123
:param function_name: The fully qualified name of the function
125124
e.g. 'azul-service-dev'
@@ -132,15 +131,9 @@ def delete_older_function_versions(self,
132131
for function in page['Versions']
133132
if (
134133
function['Version'] != '$LATEST' # The so-called "unpublished" version
135-
and int(function['Version']) <= int(keep_version)
134+
and int(function['Version']) < keep_version
136135
)
137136
]
138-
try:
139-
versions.remove(keep_version)
140-
except ValueError:
141-
assert False, R(
142-
'Function version not found',
143-
function_name, keep_version, versions)
144137
for version in versions:
145138
log.info('Deleting version %r of %r', version, function_name)
146139
self._lambda.delete_function(FunctionName=function_name,

0 commit comments

Comments
 (0)