Skip to content

Home

Build Status NuGet Downloads

A comprehensive library of reusable AWS CDK constructs for .NET projects, designed for serverless applications and static websites. Built with best practices, observability, and cost efficiency in mind.

Key Features

  • πŸš€ Lambda Functions: Comprehensive Lambda construct with configurable OpenTelemetry support, IAM management, and environment configuration
  • πŸ•ΈοΈ Web Functions: AWS Lambda Web Functions served from an S3 artifact, with IAM or application-managed endpoints, endpoint-scoped grants, and CloudFront OAC origin integration
  • 🌐 Static Sites: Complete static website hosting with S3, CloudFront, SSL certificates, and Route53 DNS management
  • πŸ”’ Private Static Assets: Immutable, versioned assets in a private bucket behind CloudFront OAC
  • πŸ“Š DynamoDB Tables: Full-featured DynamoDB construct with streams, TTL, and global secondary indexes
  • πŸ§ͺ Testing Helpers: Extensive testing utilities with fluent assertions and builders
  • πŸ“ Type Safety: Full TypeScript-style intellisense and compile-time validation
  • ⚑ Performance: Optimized for cold starts with AWS Lambda SnapStart support

Installation

dotnet add package LayeredCraft.Cdk.Constructs

Quick Start

using Amazon.CDK;
using LayeredCraft.Cdk.Constructs;
using LayeredCraft.Cdk.Constructs.Models;

public class MyStack : Stack
{
    public MyStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
    {
        // Create a Lambda function
        var lambda = new LambdaFunctionConstruct(this, "MyLambda", new LambdaFunctionConstructProps
        {
            FunctionName = "my-api",
            FunctionSuffix = "prod",
            AssetPath = "./lambda-deployment.zip",
            RoleName = "my-api-role",
            PolicyName = "my-api-policy",
            IncludeOtelLayer = true, // Enable OpenTelemetry (disabled by default in v2.0+)
            GenerateUrl = true // Creates a Function URL for HTTP access
        });

        // Create a static website
        var site = new StaticSiteConstruct(this, "MySite", new StaticSiteConstructProps
        {
            DomainName = "example.com",
            SiteSubDomain = "www",
            AssetPath = "./website-build"
        });
    }
}

Available Constructs

Lambda Function Construct

Full-featured Lambda functions with:

  • Configurable OpenTelemetry integration
  • IAM roles and policies
  • Environment variables
  • Function URLs
  • SnapStart support
  • Versioning and aliases

Web Function Construct

AWS Lambda Web Functions with:

  • S3-backed artifacts (WebFunctionCode.FromBucket)
  • IAM or application-managed endpoints
  • Endpoint-scoped invocation grants
  • CloudFront OAC origin integration
  • A single resource policy per function

Static Site Construct

Complete static website hosting with:

  • S3 website hosting
  • CloudFront CDN
  • SSL certificates
  • Route53 DNS
  • API proxy support

Private Static Assets Construct

Private, immutable web assets behind CloudFront:

  • Private S3 bucket (Block Public Access, SSE-S3, SSL-only, versioned)
  • CloudFront with origin access control, HTTPS-only by default
  • Versioned deployment prefix, no prune, retained objects, cache-control
  • Optional custom DNS, SPA routing and error responses (off by default)

DynamoDB Table Construct

Production-ready DynamoDB tables with:

  • Global secondary indexes
  • DynamoDB streams
  • TTL configuration
  • Lambda stream integration

Cognito User Pool Construct

Full-featured Cognito User Pool with:

  • Custom and Cognito-hosted domains
  • Resource servers and OAuth scopes
  • App clients with configurable OAuth flows
  • User groups
  • Managed Login v2 branding

Documentation

Requirements

  • .NET 10 or .NET 11
  • AWS CDK v2 (Amazon.CDK.Lib 2.278.0+)
  • AWS CLI configured with appropriate permissions
  • Node.js (for CDK deployment)

Contributing

See the main README for contribution guidelines.

License

This project is licensed under the MIT License.