Amazon.Lambda.Core 3.4.0
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();
}
Response Streaming
This package includes types under the Amazon.Lambda.Core.ResponseStreaming namespace that let a handler stream its response back incrementally instead of buffering the entire payload. This raises the maximum response size beyond the standard 6 MB buffered limit and lets callers receive data as soon as it is produced.
Use LambdaResponseStreamFactory to create a write-only LambdaResponseStream (a System.IO.Stream) and write to it with any standard stream consumer, such as StreamWriter. Once a handler creates a response stream, all output must be written to the stream and the handler's return value is ignored.
using Amazon.Lambda.Core.ResponseStreaming;
public async Task StreamHandler(string input, ILambdaContext context)
{
await using var responseStream = LambdaResponseStreamFactory.CreateStream();
using var writer = new StreamWriter(responseStream);
for (var i = 0; i < 5; i++)
{
await writer.WriteLineAsync($"Chunk {i}");
await writer.FlushAsync();
}
}
When the function is invoked through a Lambda Function URL or API Gateway, use CreateHttpStream(HttpResponseStreamPrelude) instead. The prelude sets the HTTP status code, headers, and cookies and is sent as the first chunk before the response body.
var prelude = new HttpResponseStreamPrelude
{
StatusCode = HttpStatusCode.OK,
Headers = { ["Content-Type"] = "text/plain" }
};
await using var responseStream = LambdaResponseStreamFactory.CreateHttpStream(prelude);
Response streaming also requires a current version of the Amazon.Lambda.RuntimeSupport package. For more details and end-to-end examples, see Announcing response streaming for .NET on AWS Lambda.
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)
{
...
}
Showing the top 20 packages that depend on Amazon.Lambda.Core.
| Packages | Downloads |
|---|---|
|
Amazon.Lambda.AspNetCoreServer.Hosting
Package for running ASP.NET Core applications using the Minimal API style as a AWS Lambda function.
|
66 |
|
Amazon.Lambda.AspNetCoreServer
Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.
|
41 |
|
Amazon.Lambda.TestUtilities
Amazon.Lambda.TestUtilties includes stub implementations of interfaces defined in Amazon.Lambda.Core and helper methods.
|
34 |
|
Amazon.Lambda.AspNetCoreServer
Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.
|
33 |
|
Amazon.Lambda.Logging.AspNetCore
Amazon Lambda .NET Core support - Logging ASP.NET Core package.
|
33 |
|
Amazon.Lambda.Serialization.SystemTextJson
Amazon Lambda .NET Core support - Serialization.Json with System.Text.Json.
|
32 |
|
Amazon.Lambda.Logging.AspNetCore
Amazon Lambda .NET Core support - Logging ASP.NET Core package.
|
32 |
|
Amazon.Lambda.TestUtilities
Amazon.Lambda.TestUtilties includes stub implementations of interfaces defined in Amazon.Lambda.Core and helper methods.
|
30 |
|
Amazon.Lambda.AspNetCoreServer
Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.
|
30 |
|
Amazon.Lambda.RuntimeSupport
Provides a bootstrap and Lambda Runtime API Client to help you to develop custom .NET Core Lambda Runtimes.
|
30 |
|
Amazon.Lambda.Serialization.Json
Amazon Lambda .NET Core support - Serialization.Json package.
|
30 |
|
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
|
30 |
|
Amazon.Lambda.RuntimeSupport
Provides a bootstrap and Lambda Runtime API Client to help you to develop custom .NET Core Lambda Runtimes.
|
29 |
|
Amazon.Lambda.AspNetCoreServer
Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.
|
29 |
|
Amazon.Lambda.Serialization.Json
Amazon Lambda .NET Core support - Serialization.Json package.
|
28 |
|
Amazon.Lambda.AspNetCoreServer
Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.
|
28 |
|
Amazon.Lambda.Annotations
Annotations that can be added to Lambda projects to generate C# code and CloudFormation templates.
|
28 |
.NET 10.0
- No dependencies.
.NET 8.0
- No dependencies.
.NET Standard 2.0
- No dependencies.
| Version | Downloads | Last updated |
|---|---|---|
| 3.4.0 | 18 | 10/09/2026 |
| 3.3.0 | 28 | 08/01/2026 |
| 3.2.0 | 21 | 07/30/2026 |
| 3.1.1 | 20 | 06/29/2026 |
| 3.1.0 | 24 | 06/20/2026 |
| 3.0.0 | 25 | 05/14/2026 |
| 2.8.1 | 20 | 05/14/2026 |
| 2.8.0 | 28 | 11/12/2025 |
| 2.7.1 | 24 | 10/04/2025 |
| 2.7.0 | 25 | 08/18/2025 |
| 2.6.0 | 24 | 06/16/2025 |
| 2.5.1 | 25 | 06/16/2025 |
| 2.5.0 | 22 | 11/27/2024 |
| 2.4.0 | 17 | 11/27/2024 |
| 2.3.0 | 26 | 09/19/2024 |
| 2.2.0 | 26 | 12/11/2023 |
| 2.1.0 | 34 | 05/10/2022 |
| 2.0.0 | 31 | 08/04/2021 |
| 1.2.0 | 39 | 05/06/2021 |
| 1.1.0 | 29 | 03/30/2021 |
| 1.0.0 | 16 | 01/09/2024 |