Siemens.AspNet.Lambda.Sdk
7.5.1
Prefix Reserved
dotnet add package Siemens.AspNet.Lambda.Sdk --version 7.5.1
NuGet\Install-Package Siemens.AspNet.Lambda.Sdk -Version 7.5.1
<PackageReference Include="Siemens.AspNet.Lambda.Sdk" Version="7.5.1" />
<PackageVersion Include="Siemens.AspNet.Lambda.Sdk" Version="7.5.1" />
<PackageReference Include="Siemens.AspNet.Lambda.Sdk" />
paket add Siemens.AspNet.Lambda.Sdk --version 7.5.1
#r "nuget: Siemens.AspNet.Lambda.Sdk, 7.5.1"
#:package Siemens.AspNet.Lambda.Sdk@7.5.1
#addin nuget:?package=Siemens.AspNet.Lambda.Sdk&version=7.5.1
#tool nuget:?package=Siemens.AspNet.Lambda.Sdk&version=7.5.1
Siemens.AspNet.Lambda.Sdk
The Siemens.AspNet.Lambda.Sdk NuGet package simplifies and accelerates AWS Lambda function development using
ASP.NET-inspired middleware pipelines, structured exception handling, and pre-configured startup patterns.
📖 Overview
This SDK helps developers focus on implementing business logic by abstracting boilerplate and common concerns specific to AWS Lambda environments.
✅ Key Features
- 🚀 Quick Lambda function implementation with structured base classes.
- ⚙️ ASP.NET-like middleware pipeline support.
- 📌 Customizable startup configurations with dependency injection.
- 🔍 Structured error logging with built-in handlers.
- 🔄 JSON serialization management.
- 🛠️ Predefined logging and error handling strategies.
- 🕒 Built-in cancellation support to gracefully handle Lambda execution limits.
📦 Installation
Using the .NET CLI
dotnet add package Siemens.AspNet.Lambda.Sdk
🧠 Key Concepts
| Component | Description |
|---|---|
FunctionBase<TRequest> |
Base class for request-only Lambda implementation |
FunctionBase<TRequest, TResponse> |
Base class for request-response Lambda implementation |
FunctionHandlerBase<TStartup, TRequest> |
Lambda with custom handler and dependency injection (request-only) |
FunctionHandlerBase<TStartup, TRequest, TResponse> |
Lambda with custom handler and dependency injection |
ILambdaMiddleware<TRequest> |
Middleware interface for request-only Lambdas |
ILambdaMiddleware<TRequest, TResponse> |
Middleware interface for request-response Lambdas |
⚡ Quickstart Examples
Dockerfile and Lambda entry point
Use the fully qualified method name (InvokeAsync) as the Lambda entry point.
Sample Dockerfile entry point:
CMD ["Siemens.TestProject.InitCognitoUser::Siemens.TestProject.InitCognitoUser.Function::InvokeAsync"]
Implementing a simple Lambda function without response
public class MyFunction : FunctionBase<SQSEvent>
{
public override Task HandleAsync(SQSEvent request, ILambdaContext context, CancellationToken cancellationToken)
{
// Your Lambda logic here
}
}
Implementing a simple Lambda function with request and response
public class Function : FunctionBase<CognitoPostConfirmationEvent, CognitoPostConfirmationEvent>
{
public override Task<CognitoPostConfirmationEvent> HandleAsync(CognitoPostConfirmationEvent request,
ILambdaContext context,
CancellationToken cancellationToken)
{
// Your Lambda logic here
}
}
Implementing a Lambda function with custom handler and dependency injection
Function:
public class Function : FunctionHandlerBase<Startup, CognitoPostConfirmationEvent, CognitoPostConfirmationEvent>
{
}
Startup:
public sealed class Startup : LambdaStartup
{
protected override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
base.ConfigureServices(services, configuration);
services.AddFunctionHandler();
}
}
FunctionHandler registration:
internal static class AddFunctionHandlerExtension
{
internal static void AddFunctionHandler(this IServiceCollection services)
{
services.AddSingletonIfNotExists<IFunctionHandler<CognitoPostConfirmationEvent, CognitoPostConfirmationEvent>, FunctionHandler>();
}
}
internal sealed class FunctionHandler(IMyService service, IJsonSerializer jsonSerializer)
: IFunctionHandler<CognitoPostConfirmationEvent, CognitoPostConfirmationEvent>
{
public Task<CognitoPostConfirmationEvent> HandleAsync(CognitoPostConfirmationEvent request,
ILambdaContext context,
CancellationToken cancellationToken)
{
// Your custom logic here
}
}
📌 Cancellation and Execution Management
The SDK includes built-in cancellation token support to help gracefully handle AWS Lambda execution timeouts.
Configure the cancellation buffer time:
internal sealed class LambdaSettings
{
/// <summary>
/// Offset to trigger the cancellation token slightly before Lambda's remaining execution time ends, ensuring proper resource cleanup.
/// </summary>
public TimeSpan CancellationBufferTime { get; init; } = TimeSpan.FromSeconds(10);
}
Base Function with Cancellation Token
If you want to implement your own function handler, here is a sample how to set up such a use case
public abstract class FunctionBase<TRequest, TResponse> : FunctionWithStartupBase<LambdaStartup, TRequest, TResponse>
{
}
public abstract class FunctionWithStartupBase<TStartup, TRequest, TResponse> where TStartup : LambdaStartup, new()
{
protected ILogger Logger { get; private set; }
private readonly ILambdaPipelineExecutor<TRequest, TResponse> _pipeline;
private readonly LambdaSettings _lambdaSettings;
protected FunctionWithStartupBase()
{
var startup = new TStartup();
var serviceProvider = startup.Setup();
_pipeline = serviceProvider.GetRequiredService<ILambdaPipelineExecutor<TRequest, TResponse>>();
_lambdaSettings = serviceProvider.GetRequiredService<LambdaSettings>();
Logger = startup.Logger;
}
public async Task<TResponse> InvokeAsync(TRequest request,
ILambdaContext context)
{
var cancelAfter = context.RemainingTime.Subtract(_lambdaSettings.CancellationBufferTime);
cancelAfter = cancelAfter < TimeSpan.Zero ? TimeSpan.Zero : cancelAfter;
using var cts = new CancellationTokenSource();
cts.CancelAfter(cancelAfter);
// Do not remove "await" here, it is necessary for the pipeline to work correctly in combination with the cancellation token.
var result = await _pipeline.ExecuteAsync(request, context, HandleAsync, cts.Token).ConfigureAwait(false);
return result;
}
public abstract Task<TResponse> HandleAsync(TRequest request,
ILambdaContext context,
CancellationToken cancellationToken);
}
📌 Error Handling and Logging
Built-in structured handlers:
| Handler | Description |
|---|---|
DefaultExceptionLogHandler |
Handles general exceptions with basic structured logging, providing essential error information like message, stack trace, and context. |
ProblemDetailsExceptionLogHandler |
Processes exceptions with RFC 7807 problem details, logging structured information about HTTP API problems including status code, title, and details. |
ValidationDetailsExceptionLogHandler |
Manages validation-related exceptions, logging detailed information about validation failures including field-specific errors. |
ValidationProblemDetailsExtendedExceptionLogHandler |
Extends validation problem details with additional context, logging enhanced validation information including current values and suggested samples. |
JsonExceptionLogHandler |
Provides enhanced error details for JSON processing errors, including exact error locations, invalid values, and expected formats - offering more context than standard JSON exceptions. |
JsonReaderExceptionLogHandler |
Delivers detailed JSON parsing error information with precise syntax error locations, expected vs. actual values, and contextual details beyond standard JSON reader exceptions. |
JsonSerializationExceptionLogHandler |
Offers comprehensive serialization error details including object structure analysis, circular reference detection, and detailed type conversion errors - surpassing standard serialization error information. |
Each handler provides detailed, structured logging of exceptions, aiding rapid diagnostics and maintenance.
📚 Documentation
Detailed documentation and further examples can be found within the codebase and will soon be available online.
📢 Contributing
Contributions and feedback are welcome! Please create issues or pull requests to suggest improvements.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Siemens.AspNet.ErrorHandling.Contracts (>= 7.5.1)
- Siemens.AspNet.Lambda.Sdk.Contracts (>= 7.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.5.1 | 104 | 6/2/2026 |
| 7.5.0 | 104 | 5/12/2026 |
| 7.5.0-alpha.16 | 54 | 5/18/2026 |
| 7.5.0-alpha.15 | 49 | 5/18/2026 |
| 7.5.0-alpha.12 | 51 | 5/12/2026 |
| 7.5.0-alpha.11 | 50 | 5/12/2026 |
| 7.5.0-alpha.10 | 48 | 5/12/2026 |
| 7.5.0-alpha.3 | 53 | 5/11/2026 |
| 7.4.6 | 22 | 6/2/2026 |
| 7.4.5 | 525 | 5/24/2026 |
| 7.4.4 | 33 | 5/18/2026 |
| 7.4.3 | 27 | 5/18/2026 |
| 7.4.2 | 1,855 | 5/11/2026 |
| 7.4.1 | 24 | 5/11/2026 |
| 7.4.0 | 97 | 5/6/2026 |
| 7.3.4 | 1,074 | 5/4/2026 |
| 7.3.3 | 651 | 5/4/2026 |
| 7.3.2 | 610 | 4/28/2026 |
| 7.3.1 | 943 | 4/24/2026 |
| 7.3.0 | 276 | 4/22/2026 |