@@ -119,7 +119,7 @@ def __init__(self, stack_name: str, handlers_dir: str, config: dict) -> None:
119
119
session = boto3 .Session ()
120
120
self .s3_client = session .client ("s3" )
121
121
self .lambda_client = session .client ("lambda" )
122
- self .cf_client = session .client ("cloudformation" )
122
+ self .cfn = session .client ("cloudformation" )
123
123
self .s3_resource = session .resource ("s3" )
124
124
self .account_id = session .client ("sts" ).get_caller_identity ()["Account" ]
125
125
self .region = session .region_name
@@ -138,7 +138,7 @@ def deploy(self, Stack: Type[BaseInfrastructureStack]) -> Dict[str, str]:
138
138
return self ._transform_output (response ["Stacks" ][0 ]["Outputs" ])
139
139
140
140
def delete (self ):
141
- self .cf_client .delete_stack (StackName = self .stack_name )
141
+ self .cfn .delete_stack (StackName = self .stack_name )
142
142
143
143
def _upload_assets (self , asset_root_dir : str , asset_manifest_file : str ):
144
144
"""
@@ -181,16 +181,16 @@ def _find_files(self, directory: str) -> List:
181
181
return file_paths
182
182
183
183
def _deploy_stack (self , stack_name : str , template : dict ):
184
- response = self .cf_client .create_stack (
184
+ response = self .cfn .create_stack (
185
185
StackName = stack_name ,
186
186
TemplateBody = yaml .dump (template ),
187
187
TimeoutInMinutes = 10 ,
188
188
OnFailure = "ROLLBACK" ,
189
189
Capabilities = ["CAPABILITY_IAM" ],
190
190
)
191
- waiter = self .cf_client .get_waiter ("stack_create_complete" )
191
+ waiter = self .cfn .get_waiter ("stack_create_complete" )
192
192
waiter .wait (StackName = stack_name , WaiterConfig = {"Delay" : 10 , "MaxAttempts" : 50 })
193
- response = self .cf_client .describe_stacks (StackName = stack_name )
193
+ response = self .cfn .describe_stacks (StackName = stack_name )
194
194
return response
195
195
196
196
def _find_assets (self , asset_template : str , account_id : str , region : str ):
@@ -220,14 +220,15 @@ class BaseInfrastructureV2(ABC):
220
220
def __init__ (self , feature_name : str , handlers_dir : Path ) -> None :
221
221
self .stack_name = f"test-{ feature_name } -{ uuid4 ()} "
222
222
self .handlers_dir = handlers_dir
223
+ self .stack_outputs : Dict [str , str ] = {}
223
224
self .app = App ()
224
225
self .stack = Stack (self .app , self .stack_name )
225
226
self .session = boto3 .Session ()
226
- self .cf_client : CloudFormationClient = self .session .client ("cloudformation" )
227
+ self .cfn : CloudFormationClient = self .session .client ("cloudformation" )
228
+
227
229
# NOTE: CDK stack account and region are tokens, we need to resolve earlier
228
230
self .account_id = self .session .client ("sts" ).get_caller_identity ()["Account" ]
229
231
self .region = self .session .region_name
230
- self .stack_outputs : Dict [str , str ] = {}
231
232
232
233
def create_lambda_functions (self , function_props : Optional [Dict ] = None ):
233
234
"""Create Lambda functions available under handlers_dir
@@ -242,7 +243,7 @@ def create_lambda_functions(self, function_props: Optional[Dict] = None):
242
243
CDK Lambda FunctionProps as dictionary to override defaults
243
244
244
245
Examples
245
- -------
246
+ --------
246
247
247
248
Creating Lambda functions available in the handlers directory
248
249
@@ -310,10 +311,8 @@ def deploy(self) -> Dict[str, str]:
310
311
return self ._deploy_stack (self .stack_name , template )
311
312
312
313
def delete (self ):
313
- self .cf_client .delete_stack (StackName = self .stack_name )
314
-
315
- def get_stack_outputs (self ) -> Dict [str , str ]:
316
- return self .stack_outputs
314
+ """Delete CloudFormation Stack"""
315
+ self .cfn .delete_stack (StackName = self .stack_name )
317
316
318
317
@abstractmethod
319
318
def create_resources (self ):
@@ -351,17 +350,17 @@ def _synthesize(self) -> Tuple[Dict, Path]:
351
350
return cf_template , Path (cloud_assembly_assets_manifest_path )
352
351
353
352
def _deploy_stack (self , stack_name : str , template : Dict ) -> Dict [str , str ]:
354
- self .cf_client .create_stack (
353
+ self .cfn .create_stack (
355
354
StackName = stack_name ,
356
355
TemplateBody = yaml .dump (template ),
357
356
TimeoutInMinutes = 10 ,
358
357
OnFailure = "ROLLBACK" ,
359
358
Capabilities = ["CAPABILITY_IAM" ],
360
359
)
361
- waiter = self .cf_client .get_waiter ("stack_create_complete" )
360
+ waiter = self .cfn .get_waiter ("stack_create_complete" )
362
361
waiter .wait (StackName = stack_name , WaiterConfig = {"Delay" : 10 , "MaxAttempts" : 50 })
363
362
364
- stack_details = self .cf_client .describe_stacks (StackName = stack_name )
363
+ stack_details = self .cfn .describe_stacks (StackName = stack_name )
365
364
stack_outputs = stack_details ["Stacks" ][0 ]["Outputs" ]
366
365
self .stack_outputs = {
367
366
output ["OutputKey" ]: output ["OutputValue" ] for output in stack_outputs if output ["OutputKey" ]
0 commit comments