Execution Unit
@klotho::execution_unit
note
Currently, Klotho only supports C# execution units running on AWS Lambda that are exposed via @klotho::expose
.
Standalone C# execution units are not yet supported.
Annotate a class that extends a supported Lambda entrypoint base class with @klotho::execution_unit
to override the execution unit's default entrypoint provided by Klotho.
Supported AWS Lambda Entrypoint Base Classes
- Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
- Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction
Directives
Directive | Type | Description |
---|---|---|
id | string | (Required) The name of the execution unit. Files with the same execution unit name are guaranteed to stay together. |
keep_warm | boolean | Warning: Experimental and subject to change. Whether this execution unit should be kept warm (AWS Lambda only). |
Examples
This example specifies an AWS Lambda entrypoint class for the execution unit with the id main
when it is exposed using an Amazon API Gateway HTTP API.
CustomLambdaEntryPoint.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Amazon.Lambda.AspNetCoreServer;
/* @klotho::execution_unit {
* id = "main"
* }
*/
public class CustomLambdaEntryPoint : APIGatewayHttpApiV2ProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
// Load an ASP.NET Core startup class
builder
.UseStartup<Startup>();
}
protected override void PostMarshallRequestFeature(IHttpRequestFeature aspNetCoreRequestFeature, ApplicationLoadBalancerRequest lambdaRequest, ILambdaContext lambdaContext)
{
// Logs the method and path of each request
lambdaContext.Logger.LogLine($"Method: {aspNetCoreRequestFeature.Method}, Path: {aspNetCoreRequestFeature.Path}");
}
}
Configuration
For more information about configuring execution units, visit our execution unit configuration page.