Skip to content

A reusable library of AWS CDK constructs for .NET projects, optimized for serverless applications using Lambda, API Gateway (or Lambda URLs), DynamoDB, S3, CloudFront, and OpenTelemetry. Built for speed, observability, and cost efficiency across the LayeredCraft project ecosystem.

License

Notifications You must be signed in to change notification settings

LayeredCraft/cdk-constructs

LayeredCraft CDK Constructs

All Contributors

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.

Features

  • πŸš€ Lambda Functions: Comprehensive Lambda construct with configurable OpenTelemetry support, IAM management, and environment configuration
  • 🌐 Static Sites: Complete static website hosting with S3, CloudFront, SSL certificates, and Route53 DNS management
  • πŸ“Š 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 intellisense and compile-time validation
  • ⚑ Performance: Optimized for cold starts with AWS Lambda SnapStart support

Installation

dotnet add package LayeredCraft.Cdk.Constructs

Quick Start

Basic Lambda Function

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)
    {
        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",
            GenerateUrl = true, // Creates Function URL for HTTP access
            IncludeOtelLayer = true, // Enable OpenTelemetry (disabled by default in v2.0+)
            Architecture = "arm64", // Optional: specify architecture (default: amd64)
            EnvironmentVariables = new Dictionary<string, string>
            {
                { "ENVIRONMENT", "production" },
                { "LOG_LEVEL", "info" }
            }
        });
    }
}

Static Website

var website = new StaticSiteConstruct(this, "Website", new StaticSiteConstructProps
{
    SiteBucketName = "my-website-bucket",
    DomainName = "example.com",
    SiteSubDomain = "www",
    AssetPath = "./website-build"
});

DynamoDB Table

var table = new DynamoDbTableConstruct(this, "UserTable", new DynamoDbTableConstructProps
{
    TableName = "users",
    PartitionKey = new AttributeDefinition { AttributeName = "userId", AttributeType = AttributeType.STRING },
    GlobalSecondaryIndexes = [
        new GlobalSecondaryIndex
        {
            IndexName = "email-index",
            PartitionKey = new AttributeDefinition { AttributeName = "email", AttributeType = AttributeType.STRING },
            ProjectionType = ProjectionType.ALL
        }
    ]
});

Documentation

πŸ“– Complete Documentation

Requirements

  • .NET 8.0 or .NET 9.0
  • AWS CDK v2 (Amazon.CDK.Lib 2.203.1+)
  • AWS CLI configured with appropriate permissions
  • Node.js (for CDK deployment)

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

# Clone the repository
git clone https://github.com/LayeredCraft/cdk-constructs.git
cd cdk-constructs

# Restore dependencies
dotnet restore

# Build the project
dotnet build

# Run tests
dotnet run --project test/LayeredCraft.Cdk.Constructs.Tests/ --framework net8.0

Code Style

  • Follow C# coding conventions
  • Use meaningful names for variables and methods
  • Add XML documentation for public APIs
  • Include unit tests for new features
  • Run tests before submitting PRs

License

This project is licensed under the MIT License.

Support

Changelog

See CHANGELOG.md for details on releases and changes.


Built with ❀️ by the LayeredCraft team

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Taylor Christian
Taylor Christian

πŸ“–
Nick Cipollina
Nick Cipollina

πŸ’» πŸ“– πŸš‡

This project follows the all-contributors specification. Contributions of any kind welcome!

About

A reusable library of AWS CDK constructs for .NET projects, optimized for serverless applications using Lambda, API Gateway (or Lambda URLs), DynamoDB, S3, CloudFront, and OpenTelemetry. Built for speed, observability, and cost efficiency across the LayeredCraft project ecosystem.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

Languages