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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Conformance/

## Coverage

All nine suites are implemented (one handler project per requirement id):
All ten suites are implemented (one handler project per requirement id):

| Suite | Ids | Handlers |
|-------|-----|----------|
Expand All @@ -55,6 +55,7 @@ All nine suites are implemented (one handler project per requirement id):
| `wait_for_callback` | 7-1 .. 7-15 | 15 |
| `parallel` | 8-1 .. 8-22 (8-15 n/a) | 21 |
| `map` | 9-1 .. 9-18 (9-14 n/a) | 17 |
| `static_typing` | 12-1 .. 12-2 | 2 |

A few requirement ids have no .NET handler because the SDK intentionally lacks
the feature they exercise (e.g. per-item / whole-result serdes slots in `map`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ./build_examples.sh [operation...]
#
# Operations (default: every suite directory found next to the templates):
# step wait callback child invoke parallel map wait_for_callback wait_for_condition
# step wait callback child invoke parallel map static_typing wait_for_callback wait_for_condition
#
# Examples:
# ./build_examples.sh step
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 12-2: Parallel branch starts before registration is sealed
using Amazon.Lambda.Core;
using Amazon.Lambda.DurableExecution;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;

namespace ParallelEarlyStart;

public class Function
{
public static async Task Main(string[] args)
{
var handler = new Function();
var serializer = new DefaultLambdaJsonSerializer();
using var handlerWrapper = HandlerWrapper.GetHandlerWrapper<DurableExecutionInvocationInput, DurableExecutionInvocationOutput>(handler.Handler, serializer);
using var bootstrap = new LambdaBootstrap(handlerWrapper);
await bootstrap.RunAsync();
}

public Task<DurableExecutionInvocationOutput> Handler(
DurableExecutionInvocationInput input, ILambdaContext context)
=> DurableFunction.WrapAsync<object?, List<string>>(Workflow, input, context);

private async Task<List<string>> Workflow(object? input, IDurableContext context)
{
string firstResult;
IParallelBranch<string> second;

await using (var parallel = context.CreateParallel(
name: "early-start",
config: new ParallelConfig { MaxConcurrency = 1 }))
{
IParallelBranch<string> first = parallel.BranchAsync(
"first", (_, _) => Task.FromResult("ready"));
firstResult = await first;

second = parallel.BranchAsync(
"second", (_, _) => Task.FromResult(firstResult + "-second"));
await parallel.CompleteAsync();
}

return new List<string> { firstResult, await second };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>bootstrap</AssemblyName>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../../../src/Amazon.Lambda.Core/Amazon.Lambda.Core.csproj" />
<ProjectReference Include="../../../../../src/Amazon.Lambda.DurableExecution/Amazon.Lambda.DurableExecution.csproj" />
<ProjectReference Include="../../../../../src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" />
<ProjectReference Include="../../../../../src/Amazon.Lambda.Serialization.SystemTextJson/Amazon.Lambda.Serialization.SystemTextJson.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 12-1: Parallel with independently typed heterogeneous branch handles
using Amazon.Lambda.Core;
using Amazon.Lambda.DurableExecution;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;

namespace ParallelTypedBranches;

public class Function
{
public static async Task Main(string[] args)
{
var handler = new Function();
var serializer = new DefaultLambdaJsonSerializer();
using var handlerWrapper = HandlerWrapper.GetHandlerWrapper<DurableExecutionInvocationInput, DurableExecutionInvocationOutput>(handler.Handler, serializer);
using var bootstrap = new LambdaBootstrap(handlerWrapper);
await bootstrap.RunAsync();
}

public Task<DurableExecutionInvocationOutput> Handler(
DurableExecutionInvocationInput input, ILambdaContext context)
=> DurableFunction.WrapAsync<object?, List<object>>(Workflow, input, context);

private async Task<List<object>> Workflow(object? input, IDurableContext context)
{
IParallelBranch<string> inventory;
IParallelBranch<int> payment;
IParallelBranch<Dictionary<string, string>> quote;

await using (var parallel = context.CreateParallel(
name: "typed-branches",
config: new ParallelConfig { MaxConcurrency = 1 }))
{
inventory = parallel.BranchAsync(
"inventory", (_, _) => Task.FromResult("reserved"));
payment = parallel.BranchAsync(
"payment", (_, _) => Task.FromResult(200));
quote = parallel.BranchAsync(
"quote", (_, _) => Task.FromResult(new Dictionary<string, string>
{
["currency"] = "USD"
}));

await parallel.CompleteAsync();
}

string inventoryResult = await inventory;
int paymentResult = await payment;
Dictionary<string, string> quoteResult = await quote;
return new List<object> { inventoryResult, paymentResult, quoteResult };
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>bootstrap</AssemblyName>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../../../src/Amazon.Lambda.Core/Amazon.Lambda.Core.csproj" />
<ProjectReference Include="../../../../../src/Amazon.Lambda.DurableExecution/Amazon.Lambda.DurableExecution.csproj" />
<ProjectReference Include="../../../../../src/Amazon.Lambda.RuntimeSupport/Amazon.Lambda.RuntimeSupport.csproj" />
<ProjectReference Include="../../../../../src/Amazon.Lambda.Serialization.SystemTextJson/Amazon.Lambda.Serialization.SystemTextJson.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Durable Execution Conformance Test Examples - .NET (Static Typing)
Globals:
Function:
Runtime: dotnet8
Timeout: 60
MemorySize: 512

Resources:
DurableFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: DurableExecutionPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- lambda:CheckpointDurableExecution
- lambda:GetDurableExecutionState
Resource: '*'

ParallelTypedBranches:
Type: AWS::Serverless::Function
TestingMetadata:
TestDescription: ["12-1"]
Metadata:
BuildMethod: makefile
Properties:
CodeUri: publish/ParallelTypedBranches/
Handler: bootstrap
Description: Parallel with independently typed heterogeneous branch handles
Role:
Fn::GetAtt:
- DurableFunctionRole
- Arn
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300

ParallelEarlyStart:
Type: AWS::Serverless::Function
TestingMetadata:
TestDescription: ["12-2"]
Metadata:
BuildMethod: makefile
Properties:
CodeUri: publish/ParallelEarlyStart/
Handler: bootstrap
Description: Parallel branch completes before later branches are registered
Role:
Fn::GetAtt:
- DurableFunctionRole
- Arn
DurableConfig:
RetentionPeriodInDays: 7
ExecutionTimeout: 300
Loading