Skip to content

Add dotnet new project and item templates for MinimalLambda #349

@j-d-ha

Description

@j-d-ha

Motivation

MinimalLambda currently has examples and docs, but no dotnet new templates. New users must copy project structure, package references, launch settings, serializer/bootstrap wiring, and handler patterns by hand. This slows first-run success and makes it easier to miss Lambda/AOT/trimming conventions.

Official .NET template guidance supports both project templates and item templates via .template.config/template.json, installable from folder, .nupkg, or NuGet feed using dotnet new install. AWS Lambda's own .NET experience also relies on installable template packages (Amazon.Lambda.Templates) plus Amazon.Lambda.Tools, so MinimalLambda should meet users where they already expect Lambda project scaffolding.

Proposed solution

Add a dedicated template package, likely MinimalLambda.Templates, that ships:

Project templates

  • minimal-lambda / mlambda: basic Lambda app using MinimalLambda with DI, MapHandler, RunAsync, appsettings, and local launch settings.
  • minimal-lambda-aot / mlambda-aot: Native AOT-ready variant with PublishAot, trimming/AOT analyzer settings, Lambda-compatible serialization/runtime choices, and documented constraints.
  • Optional event-focused variants or switches:
    • SQS (MinimalLambda.Envelopes.Sqs)
    • SNS
    • API Gateway / ALB
    • Kinesis / Firehose / Kafka / CloudWatch Logs
  • Optional observability switch or variant using MinimalLambda.OpenTelemetry.
  • Optional test project generation using MinimalLambda.Testing.

Item/code templates

Provide dotnet new item templates for common MinimalLambda code snippets:

  • Handler file/class/function pattern.
  • Middleware class.
  • Lifecycle hook registration/sample.
  • Envelope handler samples for common event sources.
  • Service + DI registration sample.
  • OpenTelemetry instrumentation sample.
  • Test fixture/sample invocation.

Packaging and integration

  • Use standard .template.config/template.json metadata (identity, name, shortName, author, classifications, tags, sourceName, symbols/options).

  • Package templates as a NuGet package users can install with:

    dotnet new install MinimalLambda.Templates
  • Include template package metadata/tags so dotnet new search MinimalLambda works well.

  • Keep generated projects runnable and aligned with existing examples/ projects.

  • Add template verification in CI:

    • pack template package
    • install package from local .nupkg
    • instantiate each template with representative options
    • dotnet restore
    • dotnet build
    • run tests for generated test templates
    • run AOT publish/check for AOT template if feasible
  • Document install/update/uninstall and common commands in README/docs.

Acceptance criteria

  • Users can install templates from produced NuGet package with dotnet new install MinimalLambda.Templates.
  • dotnet new list minimal-lambda shows project and item templates with clear names, short names, language, and tags.
  • Generated basic project builds without manual edits.
  • Generated AOT project passes repo AOT verification expectations or has documented prerequisites/limitations.
  • Generated templates use current package versions and repo conventions.
  • Item templates can be added to an existing project without breaking build.
  • CI validates template package packing, install, instantiation, restore, and build.
  • Docs include quickstart:
    • install templates
    • create basic project
    • create AOT project
    • add common item template
    • uninstall/update templates

Research notes

  • .NET custom templates are folder/file based and configured through .template.config/template.json.
  • dotnet new supports project templates and item templates; item templates can output one or more files into an existing project.
  • Template packages can be installed from NuGet, local .nupkg, or folder via dotnet new install.
  • AWS Lambda .NET docs recommend Amazon.Lambda.Templates for creating Lambda projects, making a template package familiar for target users.
  • AWS Lambda Native AOT docs call out special build/deploy requirements; AOT template should encode safe defaults and document constraints.

References:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions