Skip to content

Commit 228d7f2

Browse files
committed
feat: simplify access to lambda layer arn
1 parent cda1008 commit 228d7f2

File tree

5 files changed

+21
-48
lines changed

5 files changed

+21
-48
lines changed

tests/e2e/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from tests.e2e.utils.infrastructure import LambdaLayerStack, deploy_once
44

55

6+
@pytest.fixture(scope="session")
7+
def lambda_layer_arn(lambda_layer_deployment):
8+
yield lambda_layer_deployment.get("LayerArn")
9+
10+
611
@pytest.fixture(scope="session")
712
def lambda_layer_deployment(request: pytest.FixtureRequest, tmp_path_factory: pytest.TempPathFactory, worker_id: str):
813
"""Setup and teardown logic for E2E test infrastructure

tests/e2e/logger/conftest.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66

77

88
@pytest.fixture(autouse=True, scope="module")
9-
def infrastructure(
10-
request: pytest.FixtureRequest,
11-
tmp_path_factory: pytest.TempPathFactory,
12-
worker_id: str,
13-
lambda_layer_deployment: dict,
14-
):
9+
def infrastructure(request: pytest.FixtureRequest, lambda_layer_arn: str):
1510
"""Setup and teardown logic for E2E test infrastructure
1611
1712
Parameters
1813
----------
1914
request : pytest.FixtureRequest
2015
pytest request fixture to introspect absolute path to test being executed
21-
tmp_path_factory : pytest.TempPathFactory
22-
pytest temporary path factory to discover shared tmp when multiple CPU processes are spun up
23-
worker_id : str
24-
pytest-xdist worker identification to detect whether parallelization is enabled
16+
lambda_layer_arn : str
17+
Lambda Layer ARN
2518
2619
Yields
2720
------
2821
Dict[str, str]
2922
CloudFormation Outputs from deployed infrastructure
3023
"""
31-
layer_arn = lambda_layer_deployment.get("LayerArn")
32-
stack = LoggerStack(handlers_dir=Path(f"{request.path.parent}/handlers"), layer_arn=layer_arn)
24+
stack = LoggerStack(handlers_dir=Path(f"{request.path.parent}/handlers"), layer_arn=lambda_layer_arn)
3325
try:
3426
yield stack.deploy()
3527
finally:

tests/e2e/metrics/conftest.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66

77

88
@pytest.fixture(autouse=True, scope="module")
9-
def infrastructure(
10-
request: pytest.FixtureRequest,
11-
tmp_path_factory: pytest.TempPathFactory,
12-
worker_id: str,
13-
lambda_layer_deployment: dict,
14-
):
9+
def infrastructure(request: pytest.FixtureRequest, lambda_layer_arn: str):
1510
"""Setup and teardown logic for E2E test infrastructure
1611
1712
Parameters
1813
----------
1914
request : pytest.FixtureRequest
2015
pytest request fixture to introspect absolute path to test being executed
21-
tmp_path_factory : pytest.TempPathFactory
22-
pytest temporary path factory to discover shared tmp when multiple CPU processes are spun up
23-
worker_id : str
24-
pytest-xdist worker identification to detect whether parallelization is enabled
16+
lambda_layer_arn : str
17+
Lambda Layer ARN
2518
2619
Yields
2720
------
2821
Dict[str, str]
2922
CloudFormation Outputs from deployed infrastructure
3023
"""
31-
layer_arn = lambda_layer_deployment.get("LayerArn")
32-
stack = MetricsStack(handlers_dir=Path(f"{request.path.parent}/handlers"), layer_arn=layer_arn)
24+
stack = MetricsStack(handlers_dir=Path(f"{request.path.parent}/handlers"), layer_arn=lambda_layer_arn)
3325
try:
3426
yield stack.deploy()
3527
finally:

tests/e2e/tracer/conftest.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,22 @@
66

77

88
@pytest.fixture(autouse=True, scope="module")
9-
def infrastructure(
10-
request: pytest.FixtureRequest,
11-
tmp_path_factory: pytest.TempPathFactory,
12-
worker_id: str,
13-
lambda_layer_deployment: dict,
14-
):
9+
def infrastructure(request: pytest.FixtureRequest, lambda_layer_arn: str):
1510
"""Setup and teardown logic for E2E test infrastructure
1611
1712
Parameters
1813
----------
1914
request : pytest.FixtureRequest
2015
pytest request fixture to introspect absolute path to test being executed
21-
tmp_path_factory : pytest.TempPathFactory
22-
pytest temporary path factory to discover shared tmp when multiple CPU processes are spun up
23-
worker_id : str
24-
pytest-xdist worker identification to detect whether parallelization is enabled
16+
lambda_layer_arn : str
17+
Lambda Layer ARN
2518
2619
Yields
2720
------
2821
Dict[str, str]
2922
CloudFormation Outputs from deployed infrastructure
3023
"""
31-
layer_arn = lambda_layer_deployment.get("LayerArn")
32-
stack = TracerStack(handlers_dir=Path(f"{request.path.parent}/handlers"), layer_arn=layer_arn)
24+
stack = TracerStack(handlers_dir=Path(f"{request.path.parent}/handlers"), layer_arn=lambda_layer_arn)
3325
try:
3426
yield stack.deploy()
3527
finally:

tests/e2e/utils/infrastructure.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ def create_lambda_functions(self, function_props: Optional[Dict] = None):
8787
source = Code.from_asset(f"{self.handlers_dir}")
8888
props_override = function_props or {}
8989
if not self.layer_arn:
90-
self.layer_arn = LambdaLayerStack.get_lambda_layer_arn()
90+
raise ValueError(
91+
"""Lambda Layer ARN cannot be empty when creating Lambda functions.
92+
Make sure to inject `lambda_layer_arn` fixture and pass at the constructor level"""
93+
)
9194

9295
layer = LayerVersion.from_layer_version_arn(self.stack, "layer-arn", layer_version_arn=self.layer_arn)
9396

@@ -305,14 +308,3 @@ def _create_layer(self) -> str:
305308
),
306309
)
307310
return layer.layer_version_arn
308-
309-
@classmethod
310-
def get_lambda_layer_arn(cls: "LambdaLayerStack") -> str:
311-
"""Lambda Layer deployed by LambdaLayer Stack
312-
313-
Returns
314-
-------
315-
str
316-
Lambda Layer ARN
317-
"""
318-
return cls.STACKS_OUTPUT.get(cls.FEATURE_NAME, {}).get("LayerArn")

0 commit comments

Comments
 (0)