Stacks

Foundation and application stacks provided by the starter kit and how to run them via generated npm scripts.


Learn how to create AWS CDK stacks before exploring the starter kit's stack patterns below.

FoundationStack

Source: src/stacks/foundation-stack.ts

Sets up GitHub OpenID Connect (OIDC) and an IAM role for GitHub Actions deploys, plus adds a CloudFormation Toolkit cleaner to keep CDK assets tidy.

Initializers

new FoundationStack(scope: Construct, id: string, props: FoundationStackProps)

Parameters

NameTypeDescription
scopeConstructThe scope in which to define this stack.
idstringThe scoped stack ID.
propsFoundationStackPropsStack configuration properties.

FoundationStackProps

NameTypeRequiredDescription
environmentstringYesEnvironment label used in the OIDC subject (e.g., test, production).

Resources Created

ResourceDescription
OpenID Connect Provideriam.OpenIdConnectProvider for token.actions.githubusercontent.com with client ID sts.amazonaws.com.
IAM RoleNamed GitHubActionsServiceRole by default (or override via GITHUB_DEPLOY_ROLE env var). Trusts GitHub OIDC with subject: repo:<owner>/<repo>:environment:<ENV>.
Toolkit CleanerToolkitCleaner from cloudstructs to automatically clean up old CDK assets.

Deployment Behavior

  • Only synthesized when not running a branch deployment (guarded by if (!process.env.GIT_BRANCH_REF) in src/main.ts).
  • Deploy once per AWS account/region to enable OIDC deployments.

Usage

# Deploy Foundation + Starter stacks for test env
npm run test:deploy:all

# Or deploy just the FoundationStack
npm run test:deploy:stack FoundationStack

StarterStack

Source: src/stacks/starter-stack.ts

Your application entry stack — add constructs and resources here. Shows a commented example using NetworkConstruct for a secure VPC.

Initializers

new StarterStack(scope: Construct, id: string, props?: StarterStackProps)

Parameters

NameTypeDescription
scopeConstructThe scope in which to define this stack.
idstringThe scoped stack ID.
propsStarterStackProps (optional)Stack configuration properties.

StarterStackProps

NameTypeRequiredDescription
environmentstringNoUsed for tagging and resource naming in src/main.ts.

Usage

# Synthesize and diff only the starter stack
npm run test:synth
npm run test:diff:stack StarterStack

# Deploy only the starter stack
npm run test:deploy:stack StarterStack

Generated npm scripts

Generated from .projenrc.ts for environment configs: test (branch deploys enabled) and production (branch deploys disabled).

Test Environment (Regular)

ScriptDescription
test:synthSynthesize all stacks
test:lsList all stacks
test:deploy:allDeploy all stacks
test:deploy:stack <StackName>Deploy specific stack
test:destroy:allDestroy all stacks
test:destroy:stack <StackName>Destroy specific stack
test:diff:allShow diff for all stacks
test:diff:stack <StackName>Show diff for specific stack

Test Environment (Branch)

ScriptDescription
test:branch:synthSynthesize all branch stacks
test:branch:lsList all branch stacks
test:branch:deploy:allDeploy all branch stacks
test:branch:deploy:stack <StackName>Deploy specific branch stack
test:branch:destroy:allDestroy all branch stacks
test:branch:destroy:stack <StackName>Destroy specific branch stack
test:branch:diff:allShow diff for all branch stacks
test:branch:diff:stack <StackName>Show diff for specific branch stack

Production Environment

ScriptDescription
production:synthSynthesize all stacks
production:lsList all stacks
production:deploy:allDeploy all stacks
production:deploy:stack <StackName>Deploy specific stack
production:destroy:allDestroy all stacks
production:destroy:stack <StackName>Destroy specific stack
production:diff:allShow diff for all stacks
production:diff:stack <StackName>Show diff for specific stack

Notes

  • :all operates on all stacks in the app; :stack accepts stack names as args.
  • Branch tasks inject GIT_BRANCH_REF automatically (from git rev-parse --abbrev-ref HEAD) for safe name suffixing and isolation.
  • The FoundationStack is excluded from branch deploys by design.