Skip to content

Commit

Permalink
fixup! Fix: Race between layer and Lambda update (#5927)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsotirho-ucsc committed May 16, 2024
1 parent 8a0fc83 commit e5d5938
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
15 changes: 7 additions & 8 deletions scripts/delete_lambda_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@


def main():
lambdas = Lambdas().list_lambdas()
lambdas = Lambdas().list_deployment_lambdas()
for lambda_ in lambdas:
response = aws.lambda_.list_versions_by_function(
FunctionName=lambda_.name
)
log.info('Fetching the published versions of %s', lambda_.name)
response = aws.lambda_.list_versions_by_function(FunctionName=lambda_.name)
for version in response['Versions']:
if version['Version'] == '$LATEST':
version = version['Version']
if version == '$LATEST':
pass
else:
version_number = version['Version']
log.info('Deleting published version %s of %s', version_number, lambda_.name)
log.info('Deleting published version %s of %s', version, lambda_.name)
aws.lambda_.delete_function(
FunctionName=lambda_.name,
Qualifier=version_number
Qualifier=version
)


Expand Down
15 changes: 15 additions & 0 deletions src/azul/lambdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,27 @@ def _lambda(self):
return aws.lambda_

def list_lambdas(self) -> list[Lambda]:
"""
Return a list of all the Lambda functions in the AWS project
"""
return [
Lambda.from_response(function)
for response in self._lambda.get_paginator('list_functions').paginate()
for function in response['Functions']
]

def list_deployment_lambdas(self) -> list[Lambda]:
"""
Return a list of all the Lambda functions that are part of the currently
selected deployment.
"""
return [
Lambda.from_response(function)
for response in self._lambda.get_paginator('list_functions').paginate()
for function in response['Functions']
if function['Environment']['Variables']['AZUL_DEPLOYMENT_STAGE'] == config.deployment_stage
]

def manage_lambdas(self, enabled: bool):
paginator = self._lambda.get_paginator('list_functions')
lambda_prefixes = [config.qualified_resource_name(lambda_infix) for lambda_infix in config.lambda_names()]
Expand Down
4 changes: 2 additions & 2 deletions src/azul/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,8 @@ def tf_config(self, app_name):
assert 'layers' not in resource
resource['layers'] = ['${aws_lambda_layer_version.dependencies.arn}']
# Publishing the Lambda function as a new version prevents possible
# race conditions when an update to the function's configuration and
# code rely on the update of each other in order to work correctly.
# race conditions when there's a cyclic dependency between an update
# to the function's configuration and an update to its code
resource['publish'] = True
env = config.es_endpoint_env(
es_endpoint=(
Expand Down

0 comments on commit e5d5938

Please sign in to comment.