Skip to content

Commit 13df083

Browse files
committed
chore: document remaining changes, cleanup
1 parent 47f41e6 commit 13df083

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

tests/e2e/metrics/test_metrics.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,3 @@ def test_cold_start_metric(cold_start_fn_arn: str, cold_start_fn: str):
6565
# THEN
6666
metric_data = metrics.get("Values", [])
6767
assert metric_data and metric_data[0] == 1.0
68-
69-
70-
# Abstract Infrastructure fixture parallelization work
71-
# helpers: adjust retries and wait to be much smaller
72-
# helpers: make retry config adjustable

tests/e2e/utils/asset.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,35 @@
22
import json
33
import zipfile
44
from pathlib import Path
5-
from typing import TYPE_CHECKING, List, Optional
5+
from typing import List, Optional
66

77
import boto3
88
import botocore.exceptions
9+
from mypy_boto3_s3 import S3Client
910

1011
from aws_lambda_powertools import Logger
1112
from tests.e2e.utils.models import AssetTemplateConfig, TemplateAssembly
1213

13-
if TYPE_CHECKING:
14-
from mypy_boto3_s3 import S3Client
15-
16-
1714
logger = Logger(service="e2e-utils")
1815

1916

2017
class Asset:
2118
def __init__(
22-
self, config: AssetTemplateConfig, account_id: str, region: str, boto3_client: Optional["S3Client"] = None
19+
self, config: AssetTemplateConfig, account_id: str, region: str, boto3_client: Optional[S3Client] = None
2320
) -> None:
21+
"""CDK Asset logic to verify existence and resolve deeply nested configuration
22+
23+
Parameters
24+
----------
25+
config : AssetTemplateConfig
26+
CDK Asset configuration found in synthesized template
27+
account_id : str
28+
AWS Account ID
29+
region : str
30+
AWS Region
31+
boto3_client : Optional["S3Client"], optional
32+
S3 client instance for asset operations, by default None
33+
"""
2434
self.config = config
2535
self.s3 = boto3_client or boto3.client("s3")
2636
self.account_id = account_id
@@ -47,8 +57,21 @@ def _resolve_bucket_name(self) -> str:
4757

4858
class Assets:
4959
def __init__(
50-
self, cfn_template: Path, account_id: str, region: str, boto3_client: Optional["S3Client"] = None
60+
self, cfn_template: Path, account_id: str, region: str, boto3_client: Optional[S3Client] = None
5161
) -> None:
62+
"""CDK Assets logic to find each asset, compress, and upload
63+
64+
Parameters
65+
----------
66+
cfn_template : Path
67+
CloudFormation template synthesized (self.__synthesize)
68+
account_id : str
69+
AWS Account ID
70+
region : str
71+
AWS Region
72+
boto3_client : Optional[S3Client], optional
73+
S3 client instance for asset operations, by default None
74+
"""
5275
self.template = cfn_template
5376
self.account_id = account_id
5477
self.region = region
@@ -57,8 +80,7 @@ def __init__(
5780
self.assets_location = str(self.template.parent)
5881

5982
def upload(self):
60-
"""
61-
This method is drop-in replacement for cdk-assets package s3 upload part.
83+
"""Drop-in replacement for cdk-assets package s3 upload part.
6284
https://www.npmjs.com/package/cdk-assets.
6385
We use custom solution to avoid dependencies from nodejs ecosystem.
6486
We follow the same design cdk-assets:
@@ -96,6 +118,3 @@ def _compress_assets(self, asset: Asset) -> io.BytesIO:
96118
archive.write(asset_file, arcname=asset_file.relative_to(asset_dir))
97119
buf.seek(0)
98120
return buf
99-
100-
def __iter__(self) -> Asset:
101-
yield from self.assets

tests/e2e/utils/infrastructure.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __init__(self, stack_name: str, handlers_dir: str, config: dict) -> None:
119119
session = boto3.Session()
120120
self.s3_client = session.client("s3")
121121
self.lambda_client = session.client("lambda")
122-
self.cf_client = session.client("cloudformation")
122+
self.cfn = session.client("cloudformation")
123123
self.s3_resource = session.resource("s3")
124124
self.account_id = session.client("sts").get_caller_identity()["Account"]
125125
self.region = session.region_name
@@ -138,7 +138,7 @@ def deploy(self, Stack: Type[BaseInfrastructureStack]) -> Dict[str, str]:
138138
return self._transform_output(response["Stacks"][0]["Outputs"])
139139

140140
def delete(self):
141-
self.cf_client.delete_stack(StackName=self.stack_name)
141+
self.cfn.delete_stack(StackName=self.stack_name)
142142

143143
def _upload_assets(self, asset_root_dir: str, asset_manifest_file: str):
144144
"""
@@ -181,16 +181,16 @@ def _find_files(self, directory: str) -> List:
181181
return file_paths
182182

183183
def _deploy_stack(self, stack_name: str, template: dict):
184-
response = self.cf_client.create_stack(
184+
response = self.cfn.create_stack(
185185
StackName=stack_name,
186186
TemplateBody=yaml.dump(template),
187187
TimeoutInMinutes=10,
188188
OnFailure="ROLLBACK",
189189
Capabilities=["CAPABILITY_IAM"],
190190
)
191-
waiter = self.cf_client.get_waiter("stack_create_complete")
191+
waiter = self.cfn.get_waiter("stack_create_complete")
192192
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)
194194
return response
195195

196196
def _find_assets(self, asset_template: str, account_id: str, region: str):
@@ -220,14 +220,15 @@ class BaseInfrastructureV2(ABC):
220220
def __init__(self, feature_name: str, handlers_dir: Path) -> None:
221221
self.stack_name = f"test-{feature_name}-{uuid4()}"
222222
self.handlers_dir = handlers_dir
223+
self.stack_outputs: Dict[str, str] = {}
223224
self.app = App()
224225
self.stack = Stack(self.app, self.stack_name)
225226
self.session = boto3.Session()
226-
self.cf_client: CloudFormationClient = self.session.client("cloudformation")
227+
self.cfn: CloudFormationClient = self.session.client("cloudformation")
228+
227229
# NOTE: CDK stack account and region are tokens, we need to resolve earlier
228230
self.account_id = self.session.client("sts").get_caller_identity()["Account"]
229231
self.region = self.session.region_name
230-
self.stack_outputs: Dict[str, str] = {}
231232

232233
def create_lambda_functions(self, function_props: Optional[Dict] = None):
233234
"""Create Lambda functions available under handlers_dir
@@ -242,7 +243,7 @@ def create_lambda_functions(self, function_props: Optional[Dict] = None):
242243
CDK Lambda FunctionProps as dictionary to override defaults
243244
244245
Examples
245-
-------
246+
--------
246247
247248
Creating Lambda functions available in the handlers directory
248249
@@ -310,10 +311,8 @@ def deploy(self) -> Dict[str, str]:
310311
return self._deploy_stack(self.stack_name, template)
311312

312313
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)
317316

318317
@abstractmethod
319318
def create_resources(self):
@@ -351,17 +350,17 @@ def _synthesize(self) -> Tuple[Dict, Path]:
351350
return cf_template, Path(cloud_assembly_assets_manifest_path)
352351

353352
def _deploy_stack(self, stack_name: str, template: Dict) -> Dict[str, str]:
354-
self.cf_client.create_stack(
353+
self.cfn.create_stack(
355354
StackName=stack_name,
356355
TemplateBody=yaml.dump(template),
357356
TimeoutInMinutes=10,
358357
OnFailure="ROLLBACK",
359358
Capabilities=["CAPABILITY_IAM"],
360359
)
361-
waiter = self.cf_client.get_waiter("stack_create_complete")
360+
waiter = self.cfn.get_waiter("stack_create_complete")
362361
waiter.wait(StackName=stack_name, WaiterConfig={"Delay": 10, "MaxAttempts": 50})
363362

364-
stack_details = self.cf_client.describe_stacks(StackName=stack_name)
363+
stack_details = self.cfn.describe_stacks(StackName=stack_name)
365364
stack_outputs = stack_details["Stacks"][0]["Outputs"]
366365
self.stack_outputs = {
367366
output["OutputKey"]: output["OutputValue"] for output in stack_outputs if output["OutputKey"]

0 commit comments

Comments
 (0)