Kanject.Core.CloudFunction

Lambda hosting helpers that keep the same handler signature in dev (Kestrel) and prod (Lambda). Provides scheduled and queue-driven function entry points so non-HTTP Lambdas don't need their own host plumbing.

Install

bash
dotnet add package Kanject.Core.CloudFunction

Register

csharp
using Kanject.Core.CloudFunction.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Same handler signature in dev (Kestrel) and prod (Lambda).
builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);

// Optional: scheduled or queue-driven function entry points
builder.Services.AddCloudFunctions();

HTTP and scheduled handlers

csharp
using Kanject.Core.CloudFunction.Abstractions.Attributes;

// HTTP function — same code path as ASP.NET Core controllers under Lambda
[ApiController]
[Route("api/v1/health")]
public class HealthController(IHealthChecker checker) : ControllerBase
{
    [HttpGet]
    public Task<IActionResult> Get() => checker.GetAsync();
}

// Scheduled function — registered at deploy time as an EventBridge rule
[CloudFunction(name: "nightly-cleanup")]
[Schedule(cron: "0 2 * * ? *")]
public class NightlyCleanup(IRetentionService retention) : ICloudFunction
{
    public Task RunAsync(CancellationToken ct) => retention.PurgeExpiredAsync(ct);
}

[Schedule] becomes an EventBridge rule on deploy; the function shares the same DI container as your HTTP controllers, so dependencies like IRetentionService resolve normally.

What ships with it

  • AWS Lambda hosting wired to ASP.NET Core under HttpApi / RestApi / ALB events
  • [Schedule] → EventBridge rule registered at deploy time
  • ICloudFunction for typed, attribute-driven non-HTTP entry points
  • Cold-start friendly DI graph (singletons reused across invocations)
  • Local emulation via Amazon.Lambda.TestTool through kanject test