Learn the fundamentals of creating AWS CDK constructs before diving into the starter kit's patterns below.
BaseConstruct
Source: src/constructs/base-construct.ts
Base class that exposes environment context and safe naming helpers for branch‑based and environment deployments.
Initializers
new BaseConstruct(scope: Construct, id: string)
Creates a new instance of BaseConstruct.
Parameters
| Name | Type | Description |
|---|---|---|
| scope | Construct | The scope in which to define this construct. |
| id | string | The scoped construct ID. |
Properties
| Name | Type | Description |
|---|---|---|
| branch | string | undefined | Cleaned branch name from GIT_BRANCH_REF (undefined for main/develop/tags). |
| environment | string | Environment name from ENVIRONMENT (defaults to dev). |
| account | string | AWS account of the current stack. |
| region | string | AWS region of the current stack. |
Methods
unique
unique(name: string): string
Generates a unique, environment/branch‑suffixed resource name (max 64 chars).
Parameters:
| Name | Type | Description |
|---|---|---|
| name | string | Base name for the resource. |
Returns: string - Environment or branch-suffixed resource name.
Implementation: Internally calls createEnvResourceName helper.
Usage
import { BaseConstruct } from '../constructs';
class MyFeatureConstruct extends BaseConstruct {
constructor(scope: Construct, id: string) {
super(scope, id);
// Use environment/account/region or branch for logic or naming
const bucketName = this.unique(`data-${this.account}`);
// ...create resources
}
}
NetworkConstruct
Source: src/constructs/network-construct.ts
Creates an opinionated VPC with public/private/isolated subnets, S3 and DynamoDB gateway endpoints, VPC Flow Logs to an encrypted S3 bucket with safe naming.
Initializers
new NetworkConstruct(scope: Construct, id: string)
Creates a new VPC with environment-specific configuration.
Parameters
| Name | Type | Description |
|---|---|---|
| scope | Construct | The scope in which to define this construct. |
| id | string | The scoped construct ID. |
Behavior
| Aspect | Configuration |
|---|---|
| VPC CIDR | Environment-based: dev → 172.16.0.0/16, test → 172.17.0.0/16, otherwise 172.18.0.0/16 |
| NAT Gateways | production = 3, others = 1 |
| Subnets | 3 subnet groups (public, private with egress, isolated) across 3 AZs, /20 each |
| Flow Logs | Stored in encrypted S3 bucket with public access blocked, named via this.unique('vpc-flow-logs-<account>') |
| Gateway Endpoints | S3 and DynamoDB endpoints included |
Properties
| Name | Type | Description |
|---|---|---|
| vpc | ec2.Vpc | The created VPC instance. |
Usage
import { NetworkConstruct } from '../constructs';
// inside a Stack
const network = new NetworkConstruct(this, 'Network');
// network.vpc is available for connecting other resources