@@ -100,40 +100,41 @@ class Lambdas:
100
100
def _lambda (self ):
101
101
return aws .lambda_
102
102
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 ]:
104
107
"""
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
114
109
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.
120
117
"""
121
118
paginator = self ._lambda .get_paginator ('list_functions' )
122
119
lambda_prefixes = [
123
- config .qualified_resource_name (lambda_infix )
120
+ config .qualified_resource_name (lambda_infix , stage = deployment )
124
121
for lambda_infix in config .lambda_names ()
122
+ if deployment is not None
125
123
]
126
124
assert all (lambda_prefixes )
125
+ params = {'FunctionVersion' : 'ALL' } if all_versions else {}
127
126
return [
128
127
Lambda .from_response (function )
129
- for response in paginator .paginate (FunctionVersion = 'ALL' , MaxItems = 500 )
128
+ for response in paginator .paginate (** params )
130
129
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
+ )
133
134
]
134
135
135
136
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 ):
137
138
self .manage_lambda (lambda_ .name , enabled )
138
139
139
140
def manage_lambda (self , lambda_name : str , enable : bool ):
0 commit comments