Skip to content

Commit e5d5938

Browse files
committed
fixup! Fix: Race between layer and Lambda update (#5927)
1 parent 8a0fc83 commit e5d5938

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

scripts/delete_lambda_versions.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919

2020

2121
def main():
22-
lambdas = Lambdas().list_lambdas()
22+
lambdas = Lambdas().list_deployment_lambdas()
2323
for lambda_ in lambdas:
24-
response = aws.lambda_.list_versions_by_function(
25-
FunctionName=lambda_.name
26-
)
24+
log.info('Fetching the published versions of %s', lambda_.name)
25+
response = aws.lambda_.list_versions_by_function(FunctionName=lambda_.name)
2726
for version in response['Versions']:
28-
if version['Version'] == '$LATEST':
27+
version = version['Version']
28+
if version == '$LATEST':
2929
pass
3030
else:
31-
version_number = version['Version']
32-
log.info('Deleting published version %s of %s', version_number, lambda_.name)
31+
log.info('Deleting published version %s of %s', version, lambda_.name)
3332
aws.lambda_.delete_function(
3433
FunctionName=lambda_.name,
35-
Qualifier=version_number
34+
Qualifier=version
3635
)
3736

3837

src/azul/lambdas.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,27 @@ def _lambda(self):
9898
return aws.lambda_
9999

100100
def list_lambdas(self) -> list[Lambda]:
101+
"""
102+
Return a list of all the Lambda functions in the AWS project
103+
"""
101104
return [
102105
Lambda.from_response(function)
103106
for response in self._lambda.get_paginator('list_functions').paginate()
104107
for function in response['Functions']
105108
]
106109

110+
def list_deployment_lambdas(self) -> list[Lambda]:
111+
"""
112+
Return a list of all the Lambda functions that are part of the currently
113+
selected deployment.
114+
"""
115+
return [
116+
Lambda.from_response(function)
117+
for response in self._lambda.get_paginator('list_functions').paginate()
118+
for function in response['Functions']
119+
if function['Environment']['Variables']['AZUL_DEPLOYMENT_STAGE'] == config.deployment_stage
120+
]
121+
107122
def manage_lambdas(self, enabled: bool):
108123
paginator = self._lambda.get_paginator('list_functions')
109124
lambda_prefixes = [config.qualified_resource_name(lambda_infix) for lambda_infix in config.lambda_names()]

src/azul/terraform.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ def tf_config(self, app_name):
709709
assert 'layers' not in resource
710710
resource['layers'] = ['${aws_lambda_layer_version.dependencies.arn}']
711711
# Publishing the Lambda function as a new version prevents possible
712-
# race conditions when an update to the function's configuration and
713-
# code rely on the update of each other in order to work correctly.
712+
# race conditions when there's a cyclic dependency between an update
713+
# to the function's configuration and an update to its code
714714
resource['publish'] = True
715715
env = config.es_endpoint_env(
716716
es_endpoint=(

0 commit comments

Comments
 (0)