Skip to content

Commit cf01e0f

Browse files
authored
chore: update SAM template generation to take an argument for skipping durable config (#23)
1 parent 357e8e4 commit cf01e0f

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

examples/cli.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def bootstrap_account():
213213
return True
214214

215215

216-
def generate_sam_template():
216+
def generate_sam_template(*, skip_durable_config=False):
217217
"""Generate SAM template for all examples."""
218218
catalog = load_catalog()
219219

@@ -240,24 +240,27 @@ def generate_sam_template():
240240
}
241241

242242
for example in catalog["examples"]:
243-
function_name = example["handler"].replace("_", "").title() + "Function"
243+
# Convert handler name to PascalCase (e.g., hello_world -> HelloWorld)
244+
handler_base = example["handler"].replace(".handler", "")
245+
function_name = "".join(word.capitalize() for word in handler_base.split("_"))
244246
template["Resources"][function_name] = {
245247
"Type": "AWS::Serverless::Function",
246248
"Properties": {
247249
"CodeUri": "build/",
248-
"Handler": f"{example['handler']}.handler",
250+
"Handler": example["handler"],
249251
"Description": example["description"],
250252
},
251253
}
252254

253-
if "durableConfig" in example:
255+
if not skip_durable_config and "durableConfig" in example:
254256
template["Resources"][function_name]["Properties"]["DurableConfig"] = (
255257
example["durableConfig"]
256258
)
257259

258260
import yaml
259261

260-
with open("template.yaml", "w") as f:
262+
template_path = Path(__file__).parent / "template.yaml"
263+
with open(template_path, "w") as f:
261264
yaml.dump(template, f, default_flow_style=False, sort_keys=False)
262265

263266
return True
@@ -495,7 +498,14 @@ def main():
495498
subparsers.add_parser("list", help="List available examples")
496499

497500
# SAM template command
498-
subparsers.add_parser("sam", help="Generate SAM template for all examples")
501+
sam_parser = subparsers.add_parser(
502+
"sam", help="Generate SAM template for all examples"
503+
)
504+
sam_parser.add_argument(
505+
"--skip-durable-config",
506+
action="store_true",
507+
help="Skip adding DurableConfig properties to functions",
508+
)
499509

500510
# Deploy command
501511
deploy_parser = subparsers.add_parser("deploy", help="Deploy an example")
@@ -533,7 +543,7 @@ def main():
533543
elif args.command == "list":
534544
list_examples()
535545
elif args.command == "sam":
536-
generate_sam_template()
546+
generate_sam_template(skip_durable_config=args.skip_durable_config)
537547
elif args.command == "deploy":
538548
deploy_function(args.example_name, args.function_name)
539549
elif args.command == "invoke":

examples/template.yaml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,102 +7,102 @@ Globals:
77
MemorySize: 128
88
Environment:
99
Variables:
10-
DEX_ENDPOINT:
10+
AWS_ENDPOINT_URL_LAMBDA:
1111
Ref: LambdaEndpoint
1212
Parameters:
1313
LambdaEndpoint:
1414
Type: String
1515
Default: https://lambda.us-west-2.amazonaws.com
1616
Resources:
17-
Helloworld.HandlerFunction:
17+
HelloWorld:
1818
Type: AWS::Serverless::Function
1919
Properties:
2020
CodeUri: build/
21-
Handler: hello_world.handler.handler
21+
Handler: hello_world.handler
2222
Description: A simple hello world example with no durable operations
2323
DurableConfig:
2424
RetentionPeriodInDays: 7
2525
ExecutionTimeout: 300
26-
Step.HandlerFunction:
26+
Step:
2727
Type: AWS::Serverless::Function
2828
Properties:
2929
CodeUri: build/
30-
Handler: step.handler.handler
30+
Handler: step.handler
3131
Description: Basic usage of context.step() to checkpoint a simple operation
3232
DurableConfig:
3333
RetentionPeriodInDays: 7
3434
ExecutionTimeout: 300
35-
Stepwithname.HandlerFunction:
35+
StepWithName:
3636
Type: AWS::Serverless::Function
3737
Properties:
3838
CodeUri: build/
39-
Handler: step_with_name.handler.handler
39+
Handler: step_with_name.handler
4040
Description: Step operation with explicit name parameter
4141
DurableConfig:
4242
RetentionPeriodInDays: 7
4343
ExecutionTimeout: 300
44-
Stepwithretry.HandlerFunction:
44+
StepWithRetry:
4545
Type: AWS::Serverless::Function
4646
Properties:
4747
CodeUri: build/
48-
Handler: step_with_retry.handler.handler
48+
Handler: step_with_retry.handler
4949
Description: Usage of context.step() with retry configuration for fault tolerance
5050
DurableConfig:
5151
RetentionPeriodInDays: 7
5252
ExecutionTimeout: 300
53-
Wait.HandlerFunction:
53+
Wait:
5454
Type: AWS::Serverless::Function
5555
Properties:
5656
CodeUri: build/
57-
Handler: wait.handler.handler
57+
Handler: wait.handler
5858
Description: Basic usage of context.wait() to pause execution
5959
DurableConfig:
6060
RetentionPeriodInDays: 7
6161
ExecutionTimeout: 300
62-
Callback.HandlerFunction:
62+
Callback:
6363
Type: AWS::Serverless::Function
6464
Properties:
6565
CodeUri: build/
66-
Handler: callback.handler.handler
66+
Handler: callback.handler
6767
Description: Basic usage of context.create_callback() to create a callback for
6868
external systems
6969
DurableConfig:
7070
RetentionPeriodInDays: 7
7171
ExecutionTimeout: 300
72-
Waitforcallback.HandlerFunction:
72+
WaitForCallback:
7373
Type: AWS::Serverless::Function
7474
Properties:
7575
CodeUri: build/
76-
Handler: wait_for_callback.handler.handler
76+
Handler: wait_for_callback.handler
7777
Description: Usage of context.wait_for_callback() to wait for external system
7878
responses
7979
DurableConfig:
8080
RetentionPeriodInDays: 7
8181
ExecutionTimeout: 300
82-
Runinchildcontext.HandlerFunction:
82+
RunInChildContext:
8383
Type: AWS::Serverless::Function
8484
Properties:
8585
CodeUri: build/
86-
Handler: run_in_child_context.handler.handler
86+
Handler: run_in_child_context.handler
8787
Description: Usage of context.run_in_child_context() to execute operations in
8888
isolated contexts
8989
DurableConfig:
9090
RetentionPeriodInDays: 7
9191
ExecutionTimeout: 300
92-
Parallel.HandlerFunction:
92+
Parallel:
9393
Type: AWS::Serverless::Function
9494
Properties:
9595
CodeUri: build/
96-
Handler: parallel.handler.handler
96+
Handler: parallel.handler
9797
Description: Executing multiple durable operations in parallel
9898
DurableConfig:
9999
RetentionPeriodInDays: 7
100100
ExecutionTimeout: 300
101-
Mapoperations.HandlerFunction:
101+
MapOperations:
102102
Type: AWS::Serverless::Function
103103
Properties:
104104
CodeUri: build/
105-
Handler: map_operations.handler.handler
105+
Handler: map_operations.handler
106106
Description: Processing collections using map-like durable operations
107107
DurableConfig:
108108
RetentionPeriodInDays: 7

0 commit comments

Comments
 (0)