Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ obj/
/.vs
/.vscode
/.idea

# Local developer overrides
Directory.Build.local.props
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="all" />
</ItemGroup>

<Import Project="Directory.Build.local.props" Condition="Exists('Directory.Build.local.props')" />
</Project>
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Amazon.Lambda.Core" Version="3.1.0" />
<PackageVersion Include="AWSSDK.BedrockRuntime" Version="3.7.401.11" />
<PackageVersion Include="coverlet.collector" Version="3.1.2" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
Expand All @@ -18,6 +19,8 @@
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="Temporalio" Version="1.14.1" />
<PackageVersion Include="Temporalio.Extensions.Aws.Lambda" Version="1.14.1" />
<PackageVersion Include="Temporalio.Extensions.Aws.Lambda.OpenTelemetry" Version="1.14.1" />
<PackageVersion Include="Temporalio.Extensions.DiagnosticSource" Version="1.14.1" />
<PackageVersion Include="Temporalio.Extensions.Hosting" Version="1.14.1" />
<PackageVersion Include="Temporalio.Extensions.OpenTelemetry" Version="1.14.1" />
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Prerequisites:
* [EagerWorkflowStart](src/EagerWorkflowStart) - Demonstrates usage of Eager Workflow Start to reduce latency for workflows that start with a local activity.
* [Encryption](src/Encryption) - End-to-end encryption with Temporal payload codecs.
* [EnvConfig](src/EnvConfig) - Load client configuration from TOML files with programmatic overrides
* [LambdaWorker](src/LambdaWorker) - Run a Temporal Worker inside an AWS Lambda function.
* [Mutex](src/Mutex) - How to implement a mutex as a workflow. Demonstrates how to avoid race conditions or parallel mutually exclusive operations on the same resource.
* [NexusCancellation](src/NexusCancellation) - Demonstrates how to cancel a running Nexus operation from a caller workflow.
* [NexusContextPropagation](src/NexusContextPropagation) - Context propagation through Nexus services.
Expand Down Expand Up @@ -83,4 +84,4 @@ Can add options like:

There is also a standalone project for running tests so output is more visible. To use it, run
`dotnet run --project tests/TemporalioSamples.Tests.csproj` and can pass options after `--`, e.g. `-- -verbose` and/or
`-- -method "*.RunAsync_SimpleRun_SucceedsAfterRetry"`.
`-- -method "*.RunAsync_SimpleRun_SucceedsAfterRetry"`.
15 changes: 15 additions & 0 deletions TemporalioSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.NexusMult
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.EnvConfig", "src\EnvConfig\TemporalioSamples.EnvConfig.csproj", "{52CE80AF-09C3-4209-8A21-6CFFAA3B2B01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.LambdaWorker", "src\LambdaWorker\TemporalioSamples.LambdaWorker.csproj", "{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.Timer", "src\Timer\TemporalioSamples.Timer.csproj", "{B37B3E98-4B04-48B8-9017-F0EDEDC7BD98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemporalioSamples.UpdatableTimer", "src\UpdatableTimer\TemporalioSamples.UpdatableTimer.csproj", "{5D02DFEA-DC08-4B7B-8E26-EDAC1942D347}"
Expand Down Expand Up @@ -663,6 +665,18 @@ Global
{5D493692-53AB-4FAA-BA4D-33B1E54E9A48}.Release|x64.Build.0 = Release|Any CPU
{5D493692-53AB-4FAA-BA4D-33B1E54E9A48}.Release|x86.ActiveCfg = Release|Any CPU
{5D493692-53AB-4FAA-BA4D-33B1E54E9A48}.Release|x86.Build.0 = Release|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Debug|x64.ActiveCfg = Debug|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Debug|x64.Build.0 = Debug|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Debug|x86.ActiveCfg = Debug|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Debug|x86.Build.0 = Debug|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Release|Any CPU.Build.0 = Release|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Release|x64.ActiveCfg = Release|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Release|x64.Build.0 = Release|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Release|x86.ActiveCfg = Release|Any CPU
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -711,6 +725,7 @@ Global
{18E26AEE-5DA3-7BF8-A1AD-13A28A6C7BA3} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
{8BE23F78-7178-4924-AB45-4AF74454CC97} = {18E26AEE-5DA3-7BF8-A1AD-13A28A6C7BA3}
{52CE80AF-09C3-4209-8A21-6CFFAA3B2B01} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
{D1D6B7AD-0E12-4D8C-83BE-9CE3EB916DD7} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
{B37B3E98-4B04-48B8-9017-F0EDEDC7BD98} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
{5D02DFEA-DC08-4B7B-8E26-EDAC1942D347} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
{AF077751-E4B9-4696-93CB-74653F0BB6C4} = {1A647B41-53D0-4638-AE5A-6630BAAE45FC}
Expand Down
2 changes: 2 additions & 0 deletions src/LambdaWorker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
temporal.toml
otel-collector-config.yaml
16 changes: 16 additions & 0 deletions src/LambdaWorker/Activities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TemporalioSamples.LambdaWorker;

using Microsoft.Extensions.Logging;
using Temporalio.Activities;

public static class Activities
{
[Activity]
public static string HelloActivity(string name)
{
ActivityExecutionContext.Current.Logger.LogInformation(
"HelloActivity started with name: {Name}",
name);
return $"Hello, {name}!";
}
}
25 changes: 25 additions & 0 deletions src/LambdaWorker/Function.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace TemporalioSamples.LambdaWorker;

using Amazon.Lambda.Core;
using Temporalio.Common;
using Temporalio.Extensions.Aws.Lambda;
using Temporalio.Extensions.Aws.Lambda.OpenTelemetry;

public class LambdaFunction
{
private static readonly Func<object?, ILambdaContext, Task> WorkerHandler =
TemporalLambdaWorker.CreateHandler(
new WorkerDeploymentVersion(
LambdaWorkerSample.DeploymentName,
LambdaWorkerSample.BuildId),
Configure);

public Task HandlerAsync(Stream input, ILambdaContext context) =>
WorkerHandler(input, context);

private static void Configure(LambdaWorkerConfig config)
{
LambdaWorkerSample.ConfigureWorkerOptions(config.WorkerOptions);
LambdaWorkerOpenTelemetry.ApplyDefaults(config);
}
}
21 changes: 21 additions & 0 deletions src/LambdaWorker/LambdaWorkerSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace TemporalioSamples.LambdaWorker;

using Temporalio.Worker;

public static class LambdaWorkerSample
{
public const string TaskQueue = "serverless-task-queue-dotnet";
public const string WorkflowId = "serverless-workflow-id-1";
public const string DeploymentName = "my-app";
public const string BuildId = "build-1";

public static TemporalWorkerOptions ConfigureWorkerOptions(TemporalWorkerOptions options)
{
ArgumentNullException.ThrowIfNull(options);

options.TaskQueue = TaskQueue;
return options.
AddWorkflow<SampleWorkflow>().
AddActivity(Activities.HelloActivity);
}
}
31 changes: 31 additions & 0 deletions src/LambdaWorker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.Extensions.Logging;
using Temporalio.Client;
using Temporalio.Extensions.Aws.Lambda;
using TemporalioSamples.LambdaWorker;

if (args.Length > 0 && args[0] != "workflow")
{
Console.WriteLine("Usage: dotnet run [workflow]");
return;
}

var connectOptions = TemporalLambdaWorker.LoadClientConnectOptions();
connectOptions.LoggerFactory = LoggerFactory.Create(builder =>
builder.
AddSimpleConsole(options => options.TimestampFormat = "[HH:mm:ss] ").
SetMinimumLevel(LogLevel.Information));
var client = await TemporalClient.ConnectAsync(connectOptions);
Console.WriteLine("Connected to Temporal Service");

var workflowId = $"{LambdaWorkerSample.WorkflowId}-{Guid.NewGuid()}";
var handle = await client.StartWorkflowAsync(
(SampleWorkflow wf) => wf.RunAsync("Serverless Lambda Worker!"),
new(
id: workflowId,
taskQueue: LambdaWorkerSample.TaskQueue));

Console.WriteLine($"Started Workflow ID: {handle.Id}");
Console.WriteLine($"Started Run ID: {handle.ResultRunId}");

var result = await handle.GetResultAsync();
Console.WriteLine($"Workflow result: {result}");
Loading
Loading