Skip to content

Commit 6ae5db5

Browse files
committed
fixup! Add a deployment-specific option to list_lambdas()
1 parent fd77636 commit 6ae5db5

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/azul/lambdas.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,40 +100,41 @@ class Lambdas:
100100
def _lambda(self):
101101
return aws.lambda_
102102

103-
def list_lambdas(self) -> list[Lambda]:
103+
def list_lambdas(self,
104+
deployment: str | None = None,
105+
all_versions: bool = False
106+
) -> list[Lambda]:
104107
"""
105-
Return a list of all the AWS Lambda functions in the AWS account. Only
106-
the latest version of each AWS Lambda function will be included in the
107-
list.
108-
"""
109-
return [
110-
Lambda.from_response(function)
111-
for response in self._lambda.get_paginator('list_functions').paginate()
112-
for function in response['Functions']
113-
]
108+
Return a list of AWS Lambda functions
114109
115-
def list_deployment_lambdas(self) -> list[Lambda]:
116-
"""
117-
Return a list of all AWS Lambda functions in the current deployment. All
118-
versions (including '$LATEST') of each AWS Lambda function will be
119-
included in the list.
110+
:param deployment: Limit output to the specified deployment stage. If
111+
`None`, functions from all deployments will be
112+
returned.
113+
114+
:param all_versions: If `True`, return all versions of each AWS Lambda
115+
function (including '$LATEST'). If `False`, return
116+
only the latest version of each function.
120117
"""
121118
paginator = self._lambda.get_paginator('list_functions')
122119
lambda_prefixes = [
123-
config.qualified_resource_name(lambda_infix)
120+
config.qualified_resource_name(lambda_infix, stage=deployment)
124121
for lambda_infix in config.lambda_names()
122+
if deployment is not None
125123
]
126124
assert all(lambda_prefixes)
125+
params = {'FunctionVersion': 'ALL'} if all_versions else {}
127126
return [
128127
Lambda.from_response(function)
129-
for response in paginator.paginate(FunctionVersion='ALL', MaxItems=500)
128+
for response in paginator.paginate(**params)
130129
for function in response['Functions']
131-
if any(function['FunctionName'].startswith(prefix)
132-
for prefix in lambda_prefixes)
130+
if deployment is None or any(
131+
function['FunctionName'].startswith(prefix)
132+
for prefix in lambda_prefixes
133+
)
133134
]
134135

135136
def manage_lambdas(self, enabled: bool):
136-
for lambda_ in self.list_deployment_lambdas():
137+
for lambda_ in self.list_lambdas(deployment=config.deployment_stage):
137138
self.manage_lambda(lambda_.name, enabled)
138139

139140
def manage_lambda(self, lambda_name: str, enable: bool):

0 commit comments

Comments
 (0)