Pseudonym.Net.Library.Lambda.Core
1.2.0
See the version list below for details.
dotnet add package Pseudonym.Net.Library.Lambda.Core --version 1.2.0
NuGet\Install-Package Pseudonym.Net.Library.Lambda.Core -Version 1.2.0
<PackageReference Include="Pseudonym.Net.Library.Lambda.Core" Version="1.2.0" />
paket add Pseudonym.Net.Library.Lambda.Core --version 1.2.0
#r "nuget: Pseudonym.Net.Library.Lambda.Core, 1.2.0"
// Install Pseudonym.Net.Library.Lambda.Core as a Cake Addin #addin nuget:?package=Pseudonym.Net.Library.Lambda.Core&version=1.2.0 // Install Pseudonym.Net.Library.Lambda.Core as a Cake Tool #tool nuget:?package=Pseudonym.Net.Library.Lambda.Core&version=1.2.0
Pseudonym.Net.Library.Lambda.Core
This is a Library to streamline Lambda under one common operation or standard. It is geared towards those who are used to developing with .netcore and familiar with the concepts of dependency injection and component based architecture.
This library wraps Amazon.Lambda.Core
and provides the following benefits:
- The library contains the lambda raw entrypoint and self discovers an entry point you define through interfaces, making you implementation strongly typed from the beginning.
- Scoped Dependency Injection through the use of discoverable interfaces to configure your container.
- Wrapping of logging,
ILambdaContext
and other Amazon features to make them injectable. - Integrated Error handling to log out and return¹ any errors encountered.
- Simple, fast and easy - one class lambda with all the mess sorted for you.
Configuring the entry point
To configure the entry point using this library, you simply need to implement the ISyncLambdaRequestProcessor
interface or the IAsyncLambdaRequestProcessor
interface if you're creating an async lambda².
The generic TInput
can be the class model representative of the json you intend to pass to the lambda, this will be automatically detected and parsed into this type upon running. If your lambda is a sync lambda, you can also specify a TOutput
generic type which will be wrapped by IlambdaReponse
.
When configuring the lambda, the handler string will always be the same:
- Sync:
Pseudonym.Net.Library.Lambda.Core.Implementation::Implementation.SyncLambdaRequestProcessor::ExecuteAsync
- Async:
Pseudonym.Net.Library.Lambda.Core.Implementation::Implementation.AsyncLambdaRequestProcessor::ExecuteAsync
Note: you can only have one implementation of one of these interfaces in your solution, if not you'll receive a runtime error.
Registering Services to the Container
Once you have made your entry point, you'll need to register it to the container, along with any other services you need to. This is done by creating a class that inherits the IContainerServicesSetup
interface. There, you will have access to the container, where you can register the entry point by calling container.AddSyncHandler()
/container.AddAsyncHandler()
.
You can also register additional services as normal, as per the example below:
public class ContainerConfig : IContainerServicesSetup
{
public void Configure(IServiceCollection container)
{
//registering a Sync handler that takes an integer and responds with a string.
container.AddSyncHandler<int, string, SyncHandler>();
container.AddScoped<ScopedLambdaContext>()
.AddTransient<ILambdaContext>(sp => sp.GetRequiredService<ScopedLambdaContext>().Context)
.AddTransient<IScopedLambdaContextSetter>(sp => sp.GetRequiredService<ScopedLambdaContext>());
container.AddTransient<ILambdaSerializer>(sp => sp.GetRequiredService<JsonSerializer>());
}
}
Available helper classes
- You can resolve amazons
ILambdaContext
from anywhere in the code by injecting it into the constructor of your class, this is all made injectable behind the scenes. - You can resolve
ILambdaResponder
with a generic payload from anywhere in the code to get a wrapped helper that will build response objects for you. ** Note: If you do not want to use the standard lambdaresponse wrapper where you output is placed under the jtoken 'Data', use the.Raw()
method. - You can resolve
ILambdaSerializer
from anywhere in the code to get hold of the current lambdas serializer and its settings.
Footnotes
¹ Footnote content goes here Will only return the error if the compiled json of the error is under 6MB as that is the restriction on lambdas.
² Note, that in terms of async and sync lambdas an Sync lambda is when you essentially have a blocking lambda that returns a result, whereas an Async Lambda just runs, and does not return a result. Both Async & Sync lambdas are run in a async context in terms of .net async from System.Threading.Tasks
, please don't confuse these!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
-
.NETCoreApp 2.1
- Amazon.Lambda.Core (>= 1.1.0)
- Amazon.Lambda.Logging.AspNetCore (>= 2.3.0)
- Amazon.Lambda.Serialization.Json (>= 1.6.0)
- Microsoft.Extensions.DependencyInjection (>= 2.1.0)
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 | |
---|---|---|---|
1.4.1 | 628 | 10/22/2019 | |
1.4.0 | 511 | 10/22/2019 | |
1.3.3 | 504 | 10/21/2019 | |
1.3.2 | 513 | 10/21/2019 | |
1.3.1 | 491 | 10/21/2019 | |
1.3.0 | 478 | 10/21/2019 | |
1.2.2 | 516 | 10/14/2019 | |
1.2.1 | 640 | 10/14/2019 | |
1.2.0 | 523 | 10/14/2019 | |
1.1.2 | 492 | 10/11/2019 | |
1.1.1 | 635 | 10/11/2019 | |
1.1.0 | 652 | 10/11/2019 | |
1.0.9 | 668 | 10/11/2019 | |
1.0.8 | 569 | 10/11/2019 | |
1.0.7 | 583 | 10/11/2019 | |
1.0.6 | 558 | 10/11/2019 | |
1.0.5 | 565 | 10/11/2019 | |
1.0.4 | 563 | 10/11/2019 | |
1.0.3 | 553 | 10/11/2019 | |
1.0.2 | 573 | 10/11/2019 | |
1.0.1 | 544 | 10/11/2019 | |
1.0.0 | 570 | 10/11/2019 |