Provides reusable AWS CDK constructs for serverless .NET applications, including Lambda functions with OpenTelemetry, IAM roles, and environment configuration. Built for LayeredCraft projects using AWS CDK in C#.
$ dotnet add package LayeredCraft.Cdk.ConstructsA 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.
dotnet add package LayeredCraft.Cdk.Constructs
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" }
}
});
}
}
var website = new StaticSiteConstruct(this, "Website", new StaticSiteConstructProps
{
DomainName = "example.com",
SiteSubDomain = "www",
AssetPath = "./website-build"
});
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
}
]
});
We welcome contributions! Please see our Contributing Guidelines for details.
# 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
This project is licensed under the MIT License.
See CHANGELOG.md for details on releases and changes.
Built with ❤️ by the LayeredCraft team
Thanks goes to these wonderful people (emoji key):
Taylor Christian 📖 | Nick Cipollina 💻 📖 🚇 |
This project follows the all-contributors specification. Contributions of any kind welcome!