Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions examples/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def bootstrap_account():
return True


def generate_sam_template():
def generate_sam_template(*, skip_durable_config=False):
"""Generate SAM template for all examples."""
catalog = load_catalog()

Expand All @@ -240,24 +240,27 @@ def generate_sam_template():
}

for example in catalog["examples"]:
function_name = example["handler"].replace("_", "").title() + "Function"
# Convert handler name to PascalCase (e.g., hello_world -> HelloWorld)
handler_base = example["handler"].replace(".handler", "")
function_name = "".join(word.capitalize() for word in handler_base.split("_"))
template["Resources"][function_name] = {
"Type": "AWS::Serverless::Function",
"Properties": {
"CodeUri": "build/",
"Handler": f"{example['handler']}.handler",
"Handler": example["handler"],
"Description": example["description"],
},
}

if "durableConfig" in example:
if not skip_durable_config and "durableConfig" in example:
template["Resources"][function_name]["Properties"]["DurableConfig"] = (
example["durableConfig"]
)

import yaml

with open("template.yaml", "w") as f:
template_path = Path(__file__).parent / "template.yaml"
with open(template_path, "w") as f:
yaml.dump(template, f, default_flow_style=False, sort_keys=False)

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

# SAM template command
subparsers.add_parser("sam", help="Generate SAM template for all examples")
sam_parser = subparsers.add_parser(
"sam", help="Generate SAM template for all examples"
)
sam_parser.add_argument(
"--skip-durable-config",
action="store_true",
help="Skip adding DurableConfig properties to functions",
)

# Deploy command
deploy_parser = subparsers.add_parser("deploy", help="Deploy an example")
Expand Down Expand Up @@ -533,7 +543,7 @@ def main():
elif args.command == "list":
list_examples()
elif args.command == "sam":
generate_sam_template()
generate_sam_template(skip_durable_config=args.skip_durable_config)
elif args.command == "deploy":
deploy_function(args.example_name, args.function_name)
elif args.command == "invoke":
Expand Down
42 changes: 21 additions & 21 deletions examples/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,102 @@ Globals:
MemorySize: 128
Environment:
Variables:
DEX_ENDPOINT:
AWS_ENDPOINT_URL_LAMBDA:
Ref: LambdaEndpoint
Parameters:
LambdaEndpoint:
Type: String
Default: https://lambda.us-west-2.amazonaws.com
Resources:
Helloworld.HandlerFunction:
HelloWorld:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: hello_world.handler.handler
Handler: hello_world.handler
Description: A simple hello world example with no durable operations
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Step.HandlerFunction:
Step:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: step.handler.handler
Handler: step.handler
Description: Basic usage of context.step() to checkpoint a simple operation
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Stepwithname.HandlerFunction:
StepWithName:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: step_with_name.handler.handler
Handler: step_with_name.handler
Description: Step operation with explicit name parameter
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Stepwithretry.HandlerFunction:
StepWithRetry:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: step_with_retry.handler.handler
Handler: step_with_retry.handler
Description: Usage of context.step() with retry configuration for fault tolerance
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Wait.HandlerFunction:
Wait:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: wait.handler.handler
Handler: wait.handler
Description: Basic usage of context.wait() to pause execution
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Callback.HandlerFunction:
Callback:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: callback.handler.handler
Handler: callback.handler
Description: Basic usage of context.create_callback() to create a callback for
external systems
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Waitforcallback.HandlerFunction:
WaitForCallback:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: wait_for_callback.handler.handler
Handler: wait_for_callback.handler
Description: Usage of context.wait_for_callback() to wait for external system
responses
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Runinchildcontext.HandlerFunction:
RunInChildContext:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: run_in_child_context.handler.handler
Handler: run_in_child_context.handler
Description: Usage of context.run_in_child_context() to execute operations in
isolated contexts
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Parallel.HandlerFunction:
Parallel:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: parallel.handler.handler
Handler: parallel.handler
Description: Executing multiple durable operations in parallel
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Mapoperations.HandlerFunction:
MapOperations:
Type: AWS::Serverless::Function
Properties:
CodeUri: build/
Handler: map_operations.handler.handler
Handler: map_operations.handler
Description: Processing collections using map-like durable operations
DurableConfig:
RetentionPeriodInDays: 7
Expand Down
Loading