Skip to content

Commit 3cd8bb0

Browse files
committed
ci: default durable examples to JSON logs
1 parent 7f364e1 commit 3cd8bb0

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

packages/aws-durable-execution-sdk-python-examples/scripts/generate_sam_template.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
DEFAULT_FUNCTION_NAME_PREFIX = "DurablePythonExample-"
10+
DEFAULT_DURABLE_LOGGING_CONFIG: dict[str, str] = {"LogFormat": "JSON"}
1011

1112

1213
def load_catalog() -> dict[str, Any]:
@@ -77,9 +78,13 @@ def build_template(examples: list[dict[str, Any]]) -> dict[str, Any]:
7778

7879
if "durableConfig" in example:
7980
properties["DurableConfig"] = example["durableConfig"]
81+
properties["LoggingConfig"] = DEFAULT_DURABLE_LOGGING_CONFIG
8082

8183
if "loggingConfig" in example:
82-
properties["LoggingConfig"] = example["loggingConfig"]
84+
properties["LoggingConfig"] = {
85+
**DEFAULT_DURABLE_LOGGING_CONFIG,
86+
**example["loggingConfig"],
87+
}
8388

8489
if "layers" in example:
8590
properties["Layers"] = example["layers"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Tests for SAM template generation."""
2+
3+
import importlib.util
4+
from pathlib import Path
5+
6+
7+
SCRIPT_PATH = (
8+
Path(__file__).resolve().parents[1] / "scripts" / "generate_sam_template.py"
9+
)
10+
SPEC = importlib.util.spec_from_file_location("generate_sam_template", SCRIPT_PATH)
11+
assert SPEC is not None
12+
assert SPEC.loader is not None
13+
generate_sam_template = importlib.util.module_from_spec(SPEC)
14+
SPEC.loader.exec_module(generate_sam_template)
15+
16+
17+
def test_build_template_adds_default_json_logging_to_durable_functions():
18+
template = generate_sam_template.build_template(
19+
[
20+
{
21+
"handler": "hello_world.handler",
22+
"description": "A durable example",
23+
"durableConfig": {
24+
"RetentionPeriodInDays": 7,
25+
"ExecutionTimeout": 300,
26+
},
27+
},
28+
{
29+
"handler": "logger_example.handler",
30+
"description": "A durable example with custom logging",
31+
"durableConfig": {
32+
"RetentionPeriodInDays": 7,
33+
"ExecutionTimeout": 300,
34+
},
35+
"loggingConfig": {"ApplicationLogLevel": "INFO"},
36+
},
37+
{
38+
"handler": "plain_lambda.handler",
39+
"description": "A non-durable example",
40+
},
41+
]
42+
)
43+
44+
resources = template["Resources"]
45+
assert resources["HelloWorld"]["Properties"]["LoggingConfig"] == {
46+
"LogFormat": "JSON"
47+
}
48+
assert resources["LoggerExample"]["Properties"]["LoggingConfig"] == {
49+
"LogFormat": "JSON",
50+
"ApplicationLogLevel": "INFO",
51+
}
52+
assert "LoggingConfig" not in resources["PlainLambda"]["Properties"]

0 commit comments

Comments
 (0)