Siemens.AspNet.Lambda.Sdk 0.1.0-alpha.195

Prefix Reserved
This is a prerelease version of Siemens.AspNet.Lambda.Sdk.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Siemens.AspNet.Lambda.Sdk --version 0.1.0-alpha.195
                    
NuGet\Install-Package Siemens.AspNet.Lambda.Sdk -Version 0.1.0-alpha.195
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Siemens.AspNet.Lambda.Sdk" Version="0.1.0-alpha.195" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Siemens.AspNet.Lambda.Sdk" Version="0.1.0-alpha.195" />
                    
Directory.Packages.props
<PackageReference Include="Siemens.AspNet.Lambda.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Siemens.AspNet.Lambda.Sdk --version 0.1.0-alpha.195
                    
#r "nuget: Siemens.AspNet.Lambda.Sdk, 0.1.0-alpha.195"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Siemens.AspNet.Lambda.Sdk@0.1.0-alpha.195
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Siemens.AspNet.Lambda.Sdk&version=0.1.0-alpha.195&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Siemens.AspNet.Lambda.Sdk&version=0.1.0-alpha.195&prerelease
                    
Install as a Cake Tool

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 Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.0-alpha.267 11 8/27/2025
0.1.0-alpha.266 10 8/27/2025
0.1.0-alpha.264 87 8/22/2025
0.1.0-alpha.263 44 8/22/2025
0.1.0-alpha.262 46 8/22/2025
0.1.0-alpha.261 50 8/22/2025
0.1.0-alpha.260 58 8/22/2025
0.1.0-alpha.259 57 8/22/2025
0.1.0-alpha.258 122 8/19/2025
0.1.0-alpha.257 185 8/18/2025
0.1.0-alpha.246 151 8/14/2025
0.1.0-alpha.245 118 8/14/2025
0.1.0-alpha.244 139 8/14/2025
0.1.0-alpha.243 118 8/14/2025
0.1.0-alpha.238 120 8/12/2025
0.1.0-alpha.237 447 8/6/2025
0.1.0-alpha.236 222 8/5/2025
0.1.0-alpha.235 198 8/5/2025
0.1.0-alpha.234 197 8/5/2025
0.1.0-alpha.233 162 8/4/2025
0.1.0-alpha.232 173 8/4/2025
0.1.0-alpha.231 69 8/1/2025
0.1.0-alpha.230 69 8/1/2025
0.1.0-alpha.229 94 7/31/2025
0.1.0-alpha.228 94 7/31/2025
0.1.0-alpha.227 92 7/31/2025
0.1.0-alpha.225 91 7/31/2025
0.1.0-alpha.224 96 7/30/2025
0.1.0-alpha.222 180 7/16/2025
0.1.0-alpha.219 165 7/14/2025
0.1.0-alpha.217 76 7/11/2025
0.1.0-alpha.212 163 7/8/2025
0.1.0-alpha.211 128 7/3/2025
0.1.0-alpha.207 110 7/3/2025
0.1.0-alpha.206 250 6/30/2025
0.1.0-alpha.205 102 6/27/2025
0.1.0-alpha.202 92 6/27/2025
0.1.0-alpha.200 95 6/27/2025
0.1.0-alpha.198 97 6/27/2025
0.1.0-alpha.196 100 6/27/2025
0.1.0-alpha.195 96 6/27/2025
0.1.0-alpha.194 95 6/27/2025
0.1.0-alpha.193 97 6/27/2025
0.1.0-alpha.192 98 6/27/2025
0.1.0-alpha.191 94 6/27/2025
0.1.0-alpha.189 116 6/26/2025
0.1.0-alpha.188 118 6/26/2025
0.1.0-alpha.187 117 6/26/2025
0.1.0-alpha.186 110 6/26/2025
0.1.0-alpha.185 114 6/26/2025
0.1.0-alpha.184 111 6/26/2025
0.1.0-alpha.183 114 6/26/2025
0.1.0-alpha.182 116 6/26/2025
0.1.0-alpha.181 116 6/25/2025
0.1.0-alpha.180 119 6/24/2025
0.1.0-alpha.179 120 6/23/2025
0.1.0-alpha.178 124 6/23/2025
0.1.0-alpha.176 122 6/23/2025
0.1.0-alpha.174 125 6/19/2025
0.1.0-alpha.173 117 6/19/2025
0.1.0-alpha.172 121 6/17/2025
0.1.0-alpha.171 125 6/16/2025
0.1.0-alpha.169 120 6/16/2025
0.1.0-alpha.165 267 6/13/2025
0.1.0-alpha.164 225 6/13/2025
0.1.0-alpha.163 229 6/13/2025
0.1.0-alpha.160 260 6/12/2025
0.1.0-alpha.159 284 6/11/2025
0.1.0-alpha.158 270 6/11/2025
0.1.0-alpha.143 262 6/11/2025
0.1.0-alpha.142 261 6/11/2025
0.1.0-alpha.140 269 6/11/2025
0.1.0-alpha.139 265 6/10/2025
0.1.0-alpha.138 265 6/9/2025
0.1.0-alpha.137 48 6/7/2025
0.1.0-alpha.136 48 6/7/2025
0.1.0-alpha.135 80 6/6/2025
0.1.0-alpha.134 81 6/6/2025
0.1.0-alpha.130 130 6/5/2025
0.1.0-alpha.129 119 6/4/2025
0.1.0-alpha.128 115 6/4/2025
0.1.0-alpha.122 120 6/3/2025
0.1.0-alpha.121 124 6/1/2025
0.1.0-alpha.120 80 6/1/2025
0.1.0-alpha.118 121 5/28/2025
0.1.0-alpha.117 120 5/28/2025
0.1.0-alpha.116 119 5/28/2025
0.1.0-alpha.115 129 5/26/2025
0.1.0-alpha.114 125 5/22/2025
0.1.0-alpha.112 121 5/21/2025
0.1.0-alpha.111 129 5/20/2025
0.1.0-alpha.108 128 5/19/2025
0.1.0-alpha.104 188 5/18/2025
0.1.0-alpha.102 209 5/14/2025
0.1.0-alpha.101 205 5/14/2025
0.1.0-alpha.100 210 5/12/2025
0.1.0-alpha.99 200 5/12/2025
0.1.0-alpha.98 46 5/10/2025
0.1.0-alpha.97 49 5/10/2025
0.1.0-alpha.86 124 5/8/2025
0.1.0-alpha.85 121 5/8/2025
0.1.0-alpha.84 121 5/8/2025
0.1.0-alpha.82 126 5/7/2025
0.1.0-alpha.81 125 5/6/2025
0.1.0-alpha.76 53 5/3/2025
0.1.0-alpha.75 77 5/2/2025
0.1.0-alpha.74 75 5/2/2025