Constructs

Reusable constructs provided by the starter kit and how to use them.


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

NameTypeDescription
scopeConstructThe scope in which to define this construct.
idstringThe scoped construct ID.

Properties

NameTypeDescription
branchstring | undefinedCleaned branch name from GIT_BRANCH_REF (undefined for main/develop/tags).
environmentstringEnvironment name from ENVIRONMENT (defaults to dev).
accountstringAWS account of the current stack.
regionstringAWS region of the current stack.

Methods

unique

unique(name: string): string

Generates a unique, environment/branch‑suffixed resource name (max 64 chars).

Parameters:

NameTypeDescription
namestringBase 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

NameTypeDescription
scopeConstructThe scope in which to define this construct.
idstringThe scoped construct ID.

Behavior

AspectConfiguration
VPC CIDREnvironment-based: dev172.16.0.0/16, test172.17.0.0/16, otherwise 172.18.0.0/16
NAT Gatewaysproduction = 3, others = 1
Subnets3 subnet groups (public, private with egress, isolated) across 3 AZs, /20 each
Flow LogsStored in encrypted S3 bucket with public access blocked, named via this.unique('vpc-flow-logs-<account>')
Gateway EndpointsS3 and DynamoDB endpoints included

Properties

NameTypeDescription
vpcec2.VpcThe 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