Amazon.Lambda.Core 2.1.0 The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved

.NET 6.0 .NET Standard 2.0
Install-Package Amazon.Lambda.Core -Version 2.1.0
dotnet add package Amazon.Lambda.Core --version 2.1.0
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Amazon.Lambda.Core --version 2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Amazon.Lambda.Core, 2.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Amazon.Lambda.Core as a Cake Addin
#addin nuget:?package=Amazon.Lambda.Core&version=2.1.0

// Install Amazon.Lambda.Core as a Cake Tool
#tool nuget:?package=Amazon.Lambda.Core&version=2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Amazon.Lambda.Core

This package contains interfaces and classes that can be helpful when running your .NET code on the AWS Lambda platform.

ILambdaContext

The Amazon.Lambda.Core.ILambdaContext interface can be used in your handler function to access information about the current execution, such as the name of the current function, the memory limit, execution time remaining, and logging.

Here is an example of how this interface can be used in your handler function. The function performs a simple ToUpper content transformation, while writing some context data to Console.

public string ToUpper(string input, ILambdaContext context)
{
    Console.WriteLine("Function name: " + context.FunctionName);
    Console.WriteLine("Max mem allocated: " + context.MemoryLimitInMB);
    Console.WriteLine("Time remaining: " + context.RemainingTime);
    Console.WriteLine("CloudWatch log stream name: " + context.LogStreamName);
    Console.WriteLine("CloudWatch log group name: " + context.LogGroupName);

    return input?.ToUpper();
}

An instance of this interface is attached to any ControllerBase.Request.HttpContext instances via the Items property using the key "LAMBDA_CONTEXT / LambdaContext"

Here is an example of how you can use this interface in a controller method.

[ApiController]
public class TestController : ControllerBase
{
    [HttpGet("/[controller]")]
    public IActionResult Get()
    {
        Response.Headers.Add("Access-Control-Allow-Origin", "*"); // NOTE: Should be configured via app.UseCors in Startup.cs

        var context = (ILambdaContext)Request.HttpContext.Items[APIGatewayProxyFunction.LAMBDA_CONTEXT];
        var tmp = new
        {
            context.AwsRequestId,
            context.FunctionName,
            context.MemoryLimitInMB,
            context.LogStreamName,
            context.LogGroupName
        };
        return new OkObjectResult(tmp);
    }
}

The following sections describe various other interfaces which are accessible through the ILambdaContext.

IClientContext

The Amazon.Lambda.Core.IClientContext interface provides information about the client application and device when the Lambda function is invoked through the AWS Mobile SDK. This includes environment information such as make and model of the device, information about the application, as well as use-defined name-value pairs that describe this installation of the application. This interface can be found under ILambdaContext.ClientContext.

IClientApplication

The Amazon.Lambda.Core.IClientApplication interface provides information about the client application when the Lambda function is invoked through the AWS Mobile SDK. This includes the application title, its version, etc. This interface can be found under ILambdaContext.ClientContext.Client.

ICognitoIdentity

The Amazon.Lambda.Core.ICognitoIdentity interface provides Information about the Amazon Cognito identity provider when invoked through the AWS Mobile SDK. This includes the Amazon Cognito IdentityId and IdentityPoolId. This interface can be found under ILambdaContext.Identity.

ILambdaLogger

The Amazon.Lambda.Core.ILambdaLogger interface allows your function to log data to CloudWatch. This interface defines methods Log and LogLine. Both take a string and result in a CloudWatch Logs event, with or without a line terminator, provided that the event size is within the allowed limits.

Here is an example of how this interface can be used in your handler function. The function performs a simple ToUpper content transformation, while logging the context data.

public string ToUpper(string input, ILambdaContext context)
{
    context.Logger.Log("Function name: " + context.FunctionName);
    context.Logger.Log("Max mem allocated: " + context.MemoryLimitInMB);
    context.Logger.Log("Time remaining: " + context.RemainingTime);

    return input?.ToUpper();
}

ILambdaSerializer

The Amazon.Lambda.Core.ILambdaSerializer interface allows you to implement a custom serializer to convert between arbitrary types and Lambda streams.

By default, Lambda functions can only use Stream types as inputs or outputs. To use other types, you can either write your own serializer that implements ILambdaSerializer, or use the Amazon.Lambda.Serialization.Json package to serialize and deserialize JSON data.

See Amazon.Lambda.Serialization.Json.JsonSerializer class for a sample implementation of ILambdaSerializer.

LambdaSerializerAttribute

The Amazon.Lambda.Core.LambdaSerializerAttribute is an attribute that can is used to instruct the Lambda container what serializer to use when converting .NET types to Lambda-supported types. This attribute can be present on the assembly or on the handler method. If you specify both, the method attribute takes priority.

Here is an example of setting this attribute on the assembly.

[assembly: Amazon.Lambda.Core.LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

And this is how the method can be applied to the handler method.

[LambdaSerializer(typeof(XmlSerializer))]
public Response CustomSerializerMethod(Request input)
{
    ...
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (113)

Showing the top 5 NuGet packages that depend on Amazon.Lambda.Core:

Package Downloads
Amazon.Lambda.Serialization.Json The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Amazon Lambda .NET Core support - Serialization.Json package.

Amazon.Lambda.Serialization.SystemTextJson The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Amazon Lambda .NET Core support - Serialization.Json with System.Text.Json.

Amazon.Lambda.Logging.AspNetCore The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Amazon Lambda .NET Core support - Logging ASP.NET Core package.

Amazon.Lambda.AspNetCoreServer The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.

Amazon.Lambda.TestUtilities The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

Amazon.Lambda.TestUtilties includes stub implementations of interfaces defined in Amazon.Lambda.Core and helper methods.

GitHub repositories (15)

Showing the top 5 popular GitHub repositories that depend on Amazon.Lambda.Core:

Repository Stars
lambci/docker-lambda
Docker images and test runners that replicate the live AWS Lambda environment
mongodb/mongo-csharp-driver
.NET Driver for MongoDB
aws/aws-lambda-dotnet
Libraries, samples and tools to help .NET Core developers develop AWS Lambda functions.
awslabs/aws-apigateway-lambda-authorizer-blueprints
Blueprints and examples for Lambda-based custom Authorizers for use in API Gateway.
exceptionless/Exceptionless.Net
Exceptionless clients for the .NET platform
Version Downloads Last updated
2.1.0 3,355,393 11/5/2021
2.0.0 4,389,235 3/30/2021
1.2.0 4,871,421 10/21/2020
1.1.0 9,830,263 2/7/2019
1.0.0 6,169,490 12/1/2016