Siemens.AspNet.Lambda.Sdk.Contracts
0.1.0-alpha.75
Prefix Reserved
See the version list below for details.
dotnet add package Siemens.AspNet.Lambda.Sdk.Contracts --version 0.1.0-alpha.75
NuGet\Install-Package Siemens.AspNet.Lambda.Sdk.Contracts -Version 0.1.0-alpha.75
<PackageReference Include="Siemens.AspNet.Lambda.Sdk.Contracts" Version="0.1.0-alpha.75" />
<PackageVersion Include="Siemens.AspNet.Lambda.Sdk.Contracts" Version="0.1.0-alpha.75" />
<PackageReference Include="Siemens.AspNet.Lambda.Sdk.Contracts" />
paket add Siemens.AspNet.Lambda.Sdk.Contracts --version 0.1.0-alpha.75
#r "nuget: Siemens.AspNet.Lambda.Sdk.Contracts, 0.1.0-alpha.75"
#addin nuget:?package=Siemens.AspNet.Lambda.Sdk.Contracts&version=0.1.0-alpha.75&prerelease
#tool nuget:?package=Siemens.AspNet.Lambda.Sdk.Contracts&version=0.1.0-alpha.75&prerelease
Siemens.AspNet.Lambda.Sdk
The Siemens.AspNet.Lambda.Sdk
NuGet package simplifies and accelerates the development of AWS Lambda functions using ASP.NET-inspired middleware pipelines, structured exception handling, and pre-configured startup patterns.
📖 Overview
This SDK enables developers to focus on implementing business logic by abstracting boilerplate and common concerns specific to AWS Lambda environments.
✅ Key Features
- 🚀 Quick implementation of Lambda functions with structured base classes.
- ⚙️ ASP.NET-like middleware pipeline support.
- 📌 Customizable startup configurations with dependency injection.
- 🔍 Structured error logging with built-in handlers for common exceptions.
- 🔄 JSON serialization management.
- 🛠️ Predefined strategies for logging and error handling.
📦 Installation
Using the .NET CLI
dotnet add package Siemens.AspNet.Lambda.Sdk
🧠 Key Concepts
Component | Description |
---|---|
FunctionBase<TRequest> |
Base class for quick Lambda implementation - request only |
FunctionBase<TRequest, TResponse> |
Base class for quick Lambda implementation - request and response |
FunctionHandlerBase<TStartup, TRequest> |
Lambda function with custom handler and dependency injection |
FunctionHandlerBase<TStartup, TRequest, TResponse> |
Lambda function with custom handler and dependency injection |
ILambdaMiddleware<TRequest> |
Interface for creating middleware for request only |
ILambdaMiddleware<TRequest, TResponse> |
Interface for creating middleware for request and response |
⚡ Quickstart Examples
Dockerfile and entry point for the lambda
Important is the method name InvokeAsync
this have to be used for your lambda json or docker file for the entry point of your lambda.
The name full qualified name of the method is used as entry point for the lambda function. The method name is used in the lambda json and docker file.
Component | Value (Sample) |
---|---|
AssemblyName | SiemensGPT.InitCognitoUser |
FunctionFullQualifiedName | SiemensGPT.InitCognitoUser.Function |
MethodName | InvokeAsync |
Result: AssemblyName::FunctionFullQualifiedName::MethodName
CMD ["SiemensGPT.InitCognitoUser::SiemensGPT.InitCognitoUser.Function::InvokeAsync"]
Sample Dockerfile:
FROM --platform=linux/amd64 public.ecr.aws/lambda/dotnet:9
WORKDIR /var/task
# This COPY command copies the .NET Lambda project's build artifacts from the host machine into the image.
# The source of the COPY should match where the .NET Lambda project publishes its build artifacts. If the Lambda function is being built
# with the AWS .NET Lambda Tooling, the `--docker-host-build-output-dir` switch controls where the .NET Lambda project
# will be built. The .NET Lambda project templates default to having `--docker-host-build-output-dir`
# set in the aws-lambda-tools-defaults.json file to "bin/Release/lambda-publish".
#
# Alternatively Docker multi-stage build could be used to build the .NET Lambda project inside the image.
# For more information on this approach checkout the project's README.md file.
COPY "bin/Release/lambda-publish" .
CMD ["SiemensGPT.InitCognitoUser::SiemensGPT.InitCognitoUser.Function::InvokeAsync"]
Sample json:
{
"Information": [
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.",
"To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.",
"dotnet lambda help",
"All the command line options for the Lambda command can be specified in this file."
],
"profile": "",
"region": "",
"configuration": "Release",
"package-type": "image",
"function-memory-size": 512,
"function-timeout": 30,
"image-command": "SiemensGPT.InitCognitoUser::SiemensGPT.InitCognitoUser.Function::InvokeAsync",
"docker-host-build-output-dir": "./bin/Release/lambda-publish",
"repository_uri": "381492162794.dkr.ecr.eu-west-1.amazonaws.com/cognito-beta-user-signup"
}
Implementing a simple Lambda function without response
public class MyFunction : FunctionBase<SQSEvent>
{
public override Task HandleAsync(SQSEvent request, ILambdaContext context)
{
// Your Lambda handling 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)
{
// Your Lambda handling 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:
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)
{
// Your custom logic here
}
}
Lambda Middleware Pipeline
Leverage middleware for clean and maintainable request handling. Sample middleware for error logging: (This middleware is already included in the SDK and active !)
internal static class AddErrorLogRequestMiddlewareExtension
{
internal static void AddErrorLogRequestMiddleware(this IServiceCollection services)
{
services.AddErrorLoggingStrategyForLambda();
services.AddSingleton(typeof(ILambdaMiddleware<>), typeof(ErrorLogRequestMiddleware<>));
}
}
internal sealed class ErrorLogRequestMiddleware<TRequest>(IErrorLoggingStrategyForLambda errorLoggingStrategy) : ILambdaMiddleware<TRequest>
{
public async Task InvokeAsync(TRequest request,
ILambdaContext context,
LambdaRequestDelegate<TRequest> requestDelegate)
{
try
{
await requestDelegate(request, context).ConfigureAwait(false);
}
catch (Exception e)
{
await errorLoggingStrategy.HandleAsync(context, e).ConfigureAwait(false);
throw;
}
}
}
📌 Error Handling and Logging
Built-in structured handlers:
DefaultExceptionLogHandler
ProblemDetailsExceptionLogHandler
ValidationDetailsExceptionLogHandler
ValidationProblemDetailsExtendedExceptionLogHandler
Each handler provides detailed, structured logging of exceptions, aiding in quick 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 | 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. |
-
net9.0
- Amazon.Lambda.AspNetCoreServer.Hosting (>= 1.8.0)
- Extensions.Pack (>= 6.0.6)
- Siemens.AspNet.ErrorHandling.Contracts (>= 5.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Siemens.AspNet.Lambda.Sdk.Contracts:
Package | Downloads |
---|---|
Siemens.AspNet.Lambda.Sdk
The Siemens.AspNet.Lambda.Sdk NuGet package simplifies and accelerates the development of AWS Lambda functions using ASP.NET-inspired middleware pipelines, structured exception handling, and pre-configured startup patterns. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.0-alpha.82 | 0 | 5/7/2025 |
0.1.0-alpha.81 | 5 | 5/6/2025 |
0.1.0-alpha.76 | 26 | 5/3/2025 |
0.1.0-alpha.75 | 52 | 5/2/2025 |
0.1.0-alpha.74 | 59 | 5/2/2025 |