![]() |
VOOZH | about |
dotnet add package Amazon.Lambda.AspNetCoreServer.Hosting --version 2.1.0
NuGet\Install-Package Amazon.Lambda.AspNetCoreServer.Hosting -Version 2.1.0
<PackageReference Include="Amazon.Lambda.AspNetCoreServer.Hosting" Version="2.1.0" />
<PackageVersion Include="Amazon.Lambda.AspNetCoreServer.Hosting" Version="2.1.0" />Directory.Packages.props
<PackageReference Include="Amazon.Lambda.AspNetCoreServer.Hosting" />Project file
paket add Amazon.Lambda.AspNetCoreServer.Hosting --version 2.1.0
#r "nuget: Amazon.Lambda.AspNetCoreServer.Hosting, 2.1.0"
#:package Amazon.Lambda.AspNetCoreServer.Hosting@2.1.0
#addin nuget:?package=Amazon.Lambda.AspNetCoreServer.Hosting&version=2.1.0Install as a Cake Addin
#tool nuget:?package=Amazon.Lambda.AspNetCoreServer.Hosting&version=2.1.0Install as a Cake Tool
This package allows ASP .NET Core applications written using the minimal api style to be deployed
as AWS Lambda functions. This is done by adding a call to AddAWSLambdaHosting to the
services collection of the application. This method takes in the LambdaEventSource enum
that configures which Lambda event source the Lambda function will be configured for.
The AddAWSLambdaHosting will setup the Amazon.Lambda.AspNetCoreServer package to process
the incoming Lambda events as ASP .NET Core requests. It will also initialize Amazon.Lambda.RuntimeSupport package to interact with the Lambda service.
This library supports .NET 6 and above. Lambda provides managed runtimes for long term supported (LTS) versions like .NET 6 and .NET 8. To use standard term supported (STS) versions like .NET 9 the Lambda function must be bundled as a self contained executable or an OCI image.
The code sample below is the typical initilization code for an ASP .NET Core application using the minimal api style. The one difference is the extra line of code calling AddAWSLambdaHosting.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Register Lambda to replace Kestrel as the web server for the ASP.NET Core application.
// If the application is not running in Lambda then this method will do nothing.
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
The Lambda function handler must be set to the assembly name (e.g., MyLambdaProject). The AddAWSLambdaHosting method sets up the Lambda runtime client and registers the callback for processing Lambda events, so the handler should not use the class library format (<assembly-name>::<full-type-name>::<method-name>).
AddAWSLambdaHosting accepts an optional HostingOptions configuration action that exposes the same customization hooks available in the traditional AbstractAspNetCoreFunction base class approach.
By default, common binary content types like image/png and application/pdf are already configured for Base64 encoding. You can register additional types or override the default encoding:
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi, options =>
{
// Register a custom binary content type
options.RegisterResponseContentEncodingForContentType("application/x-custom-binary", ResponseContentEncoding.Base64);
// Ensure compressed responses are Base64-encoded (gzip, deflate, br are already defaults)
options.RegisterResponseContentEncodingForContentEncoding("zstd", ResponseContentEncoding.Base64);
// Change the fallback encoding for any unregistered content type
options.DefaultResponseContentEncoding = ResponseContentEncoding.Base64;
});
Useful during development to surface unhandled exception details in the HTTP response body:
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi, options =>
{
options.IncludeUnhandledExceptionDetailInResponse = app.Environment.IsDevelopment();
});
Callbacks let you inspect or modify the ASP.NET Core feature objects after the Lambda event has been marshalled into them. The second parameter is the raw Lambda request or response object — cast it to the appropriate type for your event source (APIGatewayHttpApiV2ProxyRequest for HttpApi, APIGatewayProxyRequest for RestApi, ApplicationLoadBalancerRequest for ApplicationLoadBalancer).
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi, options =>
{
// Add a custom header derived from the raw Lambda request
options.PostMarshallRequestFeature = (requestFeature, lambdaRequest, context) =>
{
var apiRequest = (APIGatewayHttpApiV2ProxyRequest)lambdaRequest;
requestFeature.Headers["X-Stage"] = apiRequest.RequestContext.Stage;
};
// Inject the Lambda context into HttpContext.Items for use in middleware or controllers
options.PostMarshallItemsFeature = (itemsFeature, lambdaRequest, context) =>
{
itemsFeature.Items["MyCustomKey"] = context.FunctionName;
};
// Modify the response after it has been marshalled back to a Lambda response
options.PostMarshallResponseFeature = (responseFeature, lambdaResponse, context) =>
{
var apiResponse = (APIGatewayHttpApiV2ProxyResponse)lambdaResponse;
apiResponse.Headers ??= new Dictionary<string, string>();
apiResponse.Headers["X-Request-Id"] = context.AwsRequestId;
};
});
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on Amazon.Lambda.AspNetCoreServer.Hosting:
| Package | Downloads |
|---|---|
|
Fen.Service
Standardized Service conventions, from the opinions of the Fulfiller Enablement team. |
|
|
Siemens.AspNet.MinimalApi.Sdk
A library which contains following functions: - Siemens.AspNet.MinimalApi.Sdk |
|
|
Siemens.AspNet.DbProvider
A library which contains following functions: - Siemens.AspNet.DbProvider |
|
|
Siemens.AspNet.Lambda.Sdk.Contracts
The Siemens.AspNet.Lambda.Sdk.Contracts 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. |
|
|
JuegoFramework
Package Description |
Showing the top 2 popular GitHub repositories that depend on Amazon.Lambda.AspNetCoreServer.Hosting:
| Repository | Stars |
|---|---|
| Elfocrash/aws-videos | |
| aws-samples/serverless-dotnet-demo |
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 51,302 | 5/18/2026 |
| 2.0.0 | 31,040 | 5/7/2026 |
| 1.10.0 | 405,896 | 2/19/2026 |
| 1.9.1 | 203,159 | 1/12/2026 |
| 1.9.0 | 1,235,653 | 7/15/2025 |
| 1.8.2 | 236,970 | 6/3/2025 |
| 1.8.1 | 123,548 | 5/15/2025 |
| 1.8.0 | 128,301 | 4/25/2025 |
| 1.7.4 | 550,046 | 2/25/2025 |
| 1.7.3 | 618,068 | 11/26/2024 |
| 1.7.2 | 277,816 | 11/20/2024 |
| 1.7.1 | 722,342 | 9/5/2024 |
| 1.7.0 | 1,633,031 | 2/16/2024 |
| 1.6.1 | 484,613 | 11/14/2023 |
| 1.6.0 | 1,193,158 | 3/24/2023 |
| 1.5.1 | 132,881 | 3/1/2023 |
| 1.5.0 | 302,349 | 12/9/2022 |
| 1.4.0 | 35,529 | 12/7/2022 |
| 1.3.1 | 880,144 | 5/27/2022 |
| 1.3.0 | 118,401 | 5/18/2022 |