Skip to content

Commit 7d34af1

Browse files
author
Michal Ploski
committed
Remove alpha dependency from CDK. Fix package creation
1 parent 081b7d9 commit 7d34af1

File tree

11 files changed

+113
-78
lines changed

11 files changed

+113
-78
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ unit-test:
2525
poetry run pytest tests/unit
2626

2727
e2e-test:
28-
poetry run pytest -n 3 --dist loadscope -rP --durations=0 --durations-min=1 tests/e2e
28+
poetry run pytest -n 3 --dist loadscope --durations=0 --durations-min=1 tests/e2e
2929

3030
coverage-html:
3131
poetry run pytest -m "not (perf or e2e)" --cov=aws_lambda_powertools --cov-report=html

poetry.lock

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ python = "^3.6.2"
3131
# 2022-04-21: jmespath was removed, to be re-added once we drop python 3.6.
3232
# issue #1148
3333
aws-cdk-lib = "^2.23.0"
34-
"aws-cdk.aws-lambda-python-alpha" = "2.23.0-alpha.0"
3534
bandit = "^1.7.1"
3635
black = "^21.12b0"
3736
coverage = {extras = ["toml"], version = "^6.2"}

tests/e2e/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import datetime
22
import uuid
3+
from typing import Generator, TypedDict
34

45
import pytest
6+
from e2e.utils import helpers, infrastructure
57

6-
from tests.e2e.utils import helpers, infrastructure
8+
9+
class LambdaConfig(TypedDict):
10+
parameters: dict
11+
environment_variables: dict[str, str]
12+
13+
14+
class LambdaExecution(TypedDict):
15+
arns: dict[str, str]
16+
execution_time: datetime.datetime
717

818

919
@pytest.fixture(scope="module")
10-
def execute_lambda(config, request):
20+
def execute_lambda(config, request) -> Generator[LambdaExecution, None, None]:
1121
stack_name = f"test-lambda-{uuid.uuid4()}"
1222
test_dir = request.fspath.dirname
1323
handlers_dir = f"{test_dir}/handlers/"
@@ -24,8 +34,6 @@ def execute_lambda(config, request):
2434

2535
for name, arn in lambda_arns.items():
2636
helpers.trigger_lambda(lambda_arn=arn, client=infra.lambda_client)
27-
print(f"lambda {name} triggered")
28-
2937
yield {"arns": lambda_arns, "execution_time": execution_time}
3038
# Ensure stack deletion is triggered at the end of the test session
3139
infra.delete()

tests/e2e/logger/test_logger.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
from typing import TypedDict
2+
13
import boto3
24
import pytest
35

6+
from .. import conftest
47
from ..utils import helpers
58

69

710
@pytest.fixture(scope="module")
8-
def config():
11+
def config() -> conftest.LambdaConfig:
912
return {
1013
"parameters": {},
1114
"environment_variables": {
@@ -17,15 +20,15 @@ def config():
1720

1821

1922
@pytest.mark.e2e
20-
def test_basic_lambda_logs_visible(execute_lambda, config):
23+
def test_basic_lambda_logs_visible(execute_lambda: conftest.LambdaExecution, config: conftest.LambdaConfig):
2124
# GIVEN
2225
lambda_arn = execute_lambda["arns"]["basichandlerarn"]
2326
timestamp = int(execute_lambda["execution_time"].timestamp() * 1000)
2427
cw_client = boto3.client("logs")
2528

2629
# WHEN
2730
filtered_logs = helpers.get_logs(
28-
lambda_function_name=lambda_arn.split(":")[-1], start_time=timestamp, log_client=cw_client
31+
lambda_function_name=lambda_arn.split(":")[-1], start_time=timestamp, log_client=cw_client, run="first"
2932
)
3033

3134
# THEN
@@ -37,7 +40,7 @@ def test_basic_lambda_logs_visible(execute_lambda, config):
3740

3841

3942
@pytest.mark.e2e
40-
def test_basic_lambda_no_debug_logs_visible(execute_lambda, config):
43+
def test_basic_lambda_no_debug_logs_visible(execute_lambda: conftest.LambdaExecution, config: conftest.LambdaConfig):
4144
# GIVEN
4245
lambda_arn = execute_lambda["arns"]["basichandlerarn"]
4346
timestamp = int(execute_lambda["execution_time"].timestamp() * 1000)
@@ -55,7 +58,7 @@ def test_basic_lambda_no_debug_logs_visible(execute_lambda, config):
5558

5659

5760
@pytest.mark.e2e
58-
def test_basic_lambda_contextual_data_logged(execute_lambda):
61+
def test_basic_lambda_contextual_data_logged(execute_lambda: conftest.LambdaExecution):
5962
# GIVEN
6063
lambda_arn = execute_lambda["arns"]["basichandlerarn"]
6164
timestamp = int(execute_lambda["execution_time"].timestamp() * 1000)
@@ -79,9 +82,10 @@ def test_basic_lambda_contextual_data_logged(execute_lambda):
7982

8083

8184
@pytest.mark.e2e
82-
def test_basic_lambda_additional_key_persistence_basic_lambda(execute_lambda, config):
85+
def test_basic_lambda_additional_key_persistence_basic_lambda(
86+
execute_lambda: conftest.LambdaExecution, config: conftest.LambdaConfig
87+
):
8388
# GIVEN
84-
8589
lambda_arn = execute_lambda["arns"]["basichandlerarn"]
8690
timestamp = int(execute_lambda["execution_time"].timestamp() * 1000)
8791
cw_client = boto3.client("logs")
@@ -101,7 +105,7 @@ def test_basic_lambda_additional_key_persistence_basic_lambda(execute_lambda, co
101105

102106

103107
@pytest.mark.e2e
104-
def test_basic_lambda_empty_event_logged(execute_lambda):
108+
def test_basic_lambda_empty_event_logged(execute_lambda: conftest.LambdaExecution):
105109

106110
# GIVEN
107111
lambda_arn = execute_lambda["arns"]["basichandlerarn"]
@@ -118,7 +122,7 @@ def test_basic_lambda_empty_event_logged(execute_lambda):
118122

119123

120124
@pytest.mark.e2e
121-
def test_no_context_lambda_contextual_data_not_logged(execute_lambda):
125+
def test_no_context_lambda_contextual_data_not_logged(execute_lambda: conftest.LambdaExecution):
122126

123127
# GIVEN
124128
lambda_arn = execute_lambda["arns"]["nocontexthandlerarn"]
@@ -145,7 +149,7 @@ def test_no_context_lambda_contextual_data_not_logged(execute_lambda):
145149

146150

147151
@pytest.mark.e2e
148-
def test_no_context_lambda_event_not_logged(execute_lambda):
152+
def test_no_context_lambda_event_not_logged(execute_lambda: conftest.LambdaExecution):
149153

150154
# GIVEN
151155
lambda_arn = execute_lambda["arns"]["nocontexthandlerarn"]

tests/e2e/metrics/test_metrics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import boto3
55
import pytest
66

7+
from .. import conftest
78
from ..utils import helpers
89

910

1011
@pytest.fixture(scope="module")
11-
def config():
12+
def config() -> conftest.LambdaConfig:
1213
return {
1314
"parameters": {},
1415
"environment_variables": {
@@ -20,7 +21,7 @@ def config():
2021

2122

2223
@pytest.mark.e2e
23-
def test_basic_lambda_metric_visible(execute_lambda, config):
24+
def test_basic_lambda_metric_visible(execute_lambda: conftest.LambdaExecution, config: conftest.LambdaConfig):
2425
start_date = execute_lambda["execution_time"]
2526
end_date = start_date + datetime.timedelta(minutes=5)
2627

tests/e2e/tracer/test_tracer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import boto3
66
import pytest
77

8+
from .. import conftest
89
from ..utils import helpers
910

1011

@@ -17,7 +18,7 @@ def config():
1718

1819

1920
@pytest.mark.e2e
20-
def test_basic_lambda_trace_visible(execute_lambda, config):
21+
def test_basic_lambda_trace_visible(execute_lambda: conftest.LambdaExecution, config: conftest.LambdaConfig):
2122
lambda_arn = execute_lambda["arns"]["basichandlerarn"]
2223
start_date = execute_lambda["execution_time"]
2324
end_date = start_date + datetime.timedelta(minutes=5)

tests/e2e/utils/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The correct AWS SAM build image based on the runtime of the function will be
2+
# passed as build arg. The default allows to do `docker build .` when testing.
3+
ARG IMAGE=public.ecr.aws/sam/build-python3.7
4+
FROM $IMAGE
5+
6+
ARG PIP_INDEX_URL
7+
ARG PIP_EXTRA_INDEX_URL
8+
ARG HTTPS_PROXY
9+
10+
# Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry)
11+
RUN pip install --upgrade pip
12+
RUN pip install pipenv poetry
13+
14+
CMD [ "python" ]

tests/e2e/utils/helpers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from datetime import datetime
23
from functools import lru_cache
34
from typing import Any, Optional, Union
45

@@ -22,14 +23,14 @@ class Log(BaseModel):
2223
extra_info: Optional[str]
2324

2425

25-
def trigger_lambda(lambda_arn, client):
26+
def trigger_lambda(lambda_arn: str, client: Any):
2627
response = client.invoke(FunctionName=lambda_arn, InvocationType="RequestResponse")
2728
return response
2829

2930

3031
@lru_cache(maxsize=10, typed=False)
3132
@retry(ValueError, delay=1, jitter=1, tries=10)
32-
def get_logs(lambda_function_name: str, log_client: Any, start_time: int, **kwargs):
33+
def get_logs(lambda_function_name: str, log_client: Any, start_time: int, **kwargs: dict):
3334
response = log_client.filter_log_events(logGroupName=f"/aws/lambda/{lambda_function_name}", startTime=start_time)
3435
if not response["events"]:
3536
raise ValueError("Empty response from Cloudwatch Logs. Repeating...")
@@ -46,7 +47,9 @@ def get_logs(lambda_function_name: str, log_client: Any, start_time: int, **kwar
4647

4748
@lru_cache(maxsize=10, typed=False)
4849
@retry(ValueError, delay=1, jitter=1, tries=10)
49-
def get_metrics(namespace, cw_client, start_date, end_date, metric_name, service_name):
50+
def get_metrics(
51+
namespace: str, cw_client: Any, start_date: datetime, end_date: datetime, metric_name: str, service_name: str
52+
):
5053
response = cw_client.get_metric_data(
5154
MetricDataQueries=[
5255
{
@@ -73,7 +76,7 @@ def get_metrics(namespace, cw_client, start_date, end_date, metric_name, service
7376

7477

7578
@retry(ValueError, delay=1, jitter=1, tries=10)
76-
def get_traces(lambda_function_name: str, xray_client, start_date, end_date):
79+
def get_traces(lambda_function_name: str, xray_client: Any, start_date: datetime, end_date: datetime):
7780
paginator = xray_client.get_paginator("get_trace_summaries")
7881
response_iterator = paginator.paginate(
7982
StartTime=start_date,

0 commit comments

Comments
 (0)