Amazon.Lambda.RuntimeSupport
1.12.1
Prefix Reserved
dotnet add package Amazon.Lambda.RuntimeSupport --version 1.12.1
NuGet\Install-Package Amazon.Lambda.RuntimeSupport -Version 1.12.1
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.12.1" />
paket add Amazon.Lambda.RuntimeSupport --version 1.12.1
#r "nuget: Amazon.Lambda.RuntimeSupport, 1.12.1"
// Install Amazon.Lambda.RuntimeSupport as a Cake Addin #addin nuget:?package=Amazon.Lambda.RuntimeSupport&version=1.12.1 // Install Amazon.Lambda.RuntimeSupport as a Cake Tool #tool nuget:?package=Amazon.Lambda.RuntimeSupport&version=1.12.1
Amazon.Lambda.RuntimeSupport
The Amazon.Lambda.RuntimeSupport package is a .NET Lambda Runtime Interface Client (RIC) for the Lambda Runtime API. The Lambda Runtime Interface Client allows your runtime to receive requests from and send requests to the Lambda service. It can be used for building .NET Lambda functions as either custom runtimes or container images. Starting with the .NET 6 this is also the Lambda rutime client used in managed runtimes.
Container Image support
AWS provides base images containing all the required components to run your functions packaged as container images on AWS Lambda. Starting with the AWS Lambda .NET 5 base image Amazon.Lambda.RuntimeSupport is used as the Lambda Runtime Client. The library targets .NET Standard 2.0 and can also be used in earlier versions of .NET Core that support .NET Standard like 3.1.
In the AWS Lambda .NET base image this library is preinstalled into /var/runtime
directory. .NET Lambda
functions using the base image do not directly interact with this package. Instead they pass in an image command or a Dockerfile CMD
that indicates the
.NET code to run. The format of that parameter is <assembly-name>::<full-type-name>::<function-name>
.
Custom base container images where Amazon.Lambda.RuntimeSupport is not preinstalled the library can be included in the .NET Lambda function code as a class library. To learn how to build a .NET Lambda function using Amazon.Lambda.RuntimeSupport as a class library checkout the Using Amazon.Lambda.RuntimeSupport as a class library section in this README.
The Dockefile below shows how to build a Lambda function using a custom base image. In this case the base image is Microsoft's .NET 6 runtime image.
This Dockerfile copies the .NET Lambda function into the /var/task
directory
and then uses the dotnet CLI to execute the .NET Lambda project which will initialize the Amazon.Lambda.RuntimeSupport library and start responding to Lambda events.
FROM mcr.microsoft.com/dotnet/runtime:6.0
WORKDIR /var/task
COPY "bin/Release/net6.0/linux-x64/publish" .
ENTRYPOINT ["/usr/bin/dotnet", "exec", "/var/task/LambdaContainerCustomBase.dll"]
Using Amazon.Lambda.RuntimeSupport as a class library
Amazon.Lambda.RuntimeSupport can be used as a class library to interact with the Lambda Runtime API. This is done by adding the NuGet dependency to Amazon.Lambda.RuntimeSupport and adding a Main
function to
Lambda .NET project to initialize Amazon.Lambda.RuntimeSupport library.
The Amazon.Lambda.RuntimeSupport.LambdaBootstrap class handles initialization of the function and runs the loop that receives and handles invocations from the AWS Lambda service.
Take a look at the signature of the ToUpperAsync method in the example below. This signature is the default for function handlers when using the Amazon.Lambda.RuntimeSupport.LambdaBootstrap class.
private static MemoryStream ResponseStream = new MemoryStream();
private static JsonSerializer JsonSerializer = new JsonSerializer();
private static async Task Main(string[] args)
{
using(var bootstrap = new LambdaBootstrap(ToUpperAsync))
{
await bootstrap.RunAsync();
}
}
private static Task<InvocationResponse> ToUpperAsync(InvocationRequest invocation)
{
var input = JsonSerializer.Deserialize<string>(invocation.InputStream);
ResponseStream.SetLength(0);
JsonSerializer.Serialize(input.ToUpper(), ResponseStream);
ResponseStream.Position = 0;
return Task.FromResult(new InvocationResponse(responseStream, false));
}
The Amazon.Lambda.RuntimeSupport.HandlerWrapper class allows you to use existing handlers with LambdaBootstrap. The Amazon.Lambda.RuntimeSupport.HandlerWrapper class also takes care of deserialization and serialization for you.
private static async Task Main(string[] args)
{
using(var handlerWrapper = HandlerWrapper.GetHandlerWrapper((Func<string, ILambdaContext, string>)ToUpper, new JsonSerializer()))
using(var bootstrap = new LambdaBootstrap(handlerWrapper))
{
await bootstrap.RunAsync();
}
}
// existing handler doesn't conform to the new Amazon.Lambda.RuntimeSupport default signature
public static string ToUpper(string input, ILambdaContext context)
{
return input?.ToUpper();
}
The Amazon.Lambda.RuntimeSupport.RuntimeApiClient class handles interaction with the AWS Lambda Runtime Interface. This class is meant for advanced use cases. Under most circumstances you won't use it directly.
Below is an excerpt from the Amazon.Lambda.RuntimeSupport.LambdaBootstrap class that demonstrates how Amazon.Lambda.RuntimeSupport.RuntimeApiClient is used. Read the full source for Amazon.Lambda.RuntimeSupport.LambdaBootstrap to learn more.
internal async Task InvokeOnceAsync()
{
using (var invocation = await Client.GetNextInvocationAsync())
{
InvocationResponse response = null;
bool invokeSucceeded = false;
try
{
response = await _handler(invocation);
invokeSucceeded = true;
}
catch (Exception exception)
{
await Client.ReportInvocationErrorAsync(invocation.LambdaContext.AwsRequestId, exception);
}
if (invokeSucceeded)
{
try
{
await Client.SendResponseAsync(invocation.LambdaContext.AwsRequestId, response?.OutputStream);
}
finally
{
if (response != null && response.DisposeOutputStream)
{
response.OutputStream?.Dispose();
}
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Amazon.Lambda.Core (>= 2.5.0)
- System.Runtime.Loader (>= 4.3.0)
- System.Text.Json (>= 6.0.10)
-
net5.0
- Amazon.Lambda.Core (>= 2.5.0)
-
net6.0
- Amazon.Lambda.Core (>= 2.5.0)
-
net8.0
- Amazon.Lambda.Core (>= 2.5.0)
- SnapshotRestore.Registry (>= 1.0.0)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on Amazon.Lambda.RuntimeSupport:
Package | Downloads |
---|---|
Amazon.Lambda.AspNetCoreServer.Hosting
Package for running ASP.NET Core applications using the Minimal API style as a AWS Lambda function. |
|
Stackage.Aws.Lambda
Custom runtime for .NET console bootstrap |
|
Lambdajection.Runtime
Sets Lambdajection projects up to support custom runtimes. |
|
Abbotware.Interop.Aws.Lambda
Abbotware Interop Library for Aws Lambda - Contains helper methods, extension methods, and plugins |
|
MinimalQueues.AwsLambdaSqs
Package Description |
GitHub repositories (9)
Showing the top 5 popular GitHub repositories that depend on Amazon.Lambda.RuntimeSupport:
Repository | Stars |
---|---|
aws/aws-lambda-dotnet
Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
|
|
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
|
|
aws/aws-extensions-for-dotnet-cli
Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
|
|
aws-samples/serverless-test-samples
This repository is designed to provide guidance for implementing comprehensive test suites for serverless applications.
|
|
Elfocrash/aws-videos
|
Version | Downloads | Last updated |
---|---|---|
1.12.1 | 4,162 | 11/26/2024 |
1.12.0 | 17,923 | 11/18/2024 |
1.11.0 | 378,959 | 9/5/2024 |
1.10.0 | 2,243,694 | 10/26/2023 |
1.9.1 | 21,378 | 10/23/2023 |
1.9.0 | 17,261 | 10/13/2023 |
1.8.8 | 403,081 | 6/9/2023 |
1.8.7 | 618,672 | 4/23/2023 |
1.8.6 | 999,808 | 3/24/2023 |
1.8.5 | 25,611 | 3/22/2023 |
1.8.4 | 262,963 | 3/1/2023 |
1.8.3 | 360,839 | 1/16/2023 |
1.8.2 | 1,213,730 | 6/17/2022 |
1.8.1 | 630,796 | 5/27/2022 |
1.8.0 | 190,949 | 5/6/2022 |
1.7.0 | 469,235 | 2/2/2022 |
1.6.0 | 181,625 | 12/13/2021 |
1.5.0 | 19,296 | 11/22/2021 |
1.4.0 | 113,593 | 11/5/2021 |
1.3.0 | 485,873 | 12/2/2020 |
1.2.0 | 53,715 | 10/21/2020 |
1.1.1 | 520,484 | 4/3/2020 |
1.1.0 | 361,664 | 11/6/2019 |
1.0.0 | 304,283 | 3/18/2019 |