| name | build-and-deployment |
| description | Build commands, build order, TypeScript configuration, and CDK deployment. Use when building packages, troubleshooting build issues, or deploying stacks. |
Build and Deployment
Make Commands (Recommended)
Use make for deterministic, hermetic builds that work the same locally and in CI/CD:
make help
make install
make clean
make build-all
make build
make build-app
Code Quality Commands
make lint
make lint-fix
make format
make format-check
make format-fix
make check
CDK Commands
make synth
make diff
make deploy
make deploy-stack STACK=StackName
CI/CD Commands
make ci-check
make ci-build
make ci-deploy
Underlying npm Commands
The Makefile wraps these npm commands:
npm install
npm run clean
npm run build
npm run build:workspaces
npm run build:app
npm run lint
npm run lint:fix
npm run format
npm run format:check
npm run format:fix
npm run synth
npm run diff
npm run deploy
Build Order
The build process ensures packages are built in dependency order:
- Root package (
src/) - Built first
- Base packages (
aws) - No internal dependencies
- Dependent packages (
codeartifact) - Built after dependencies
- CDK app (
bin/, lib/) - Built last, can import from all packages
Build Script Details
The build:workspaces script:
- Builds root package (
npm run build)
- Copies root to
node_modules/@cdk-constructs/cdk/ for workspace resolution
- Builds all workspace packages using TypeScript project references
- Builds CDK app files (
bin/, lib/)
TypeScript Configuration
Root Package (tsconfig.json)
- Builds
src/**/* only
- Excludes
bin/, lib/, and packages/
CDK App (tsconfig.app.json)
- Builds
bin/**/* and lib/**/*
- Can import from workspace packages after they're built
Workspace Build (tsconfig.build.json)
- Lists packages in dependency order
- Uses TypeScript project references for incremental builds
Deployment Patterns
Multi-Account Strategy
This project follows a strict multi-account deployment pattern for security, isolation, and supply chain integrity.
Account Structure
| Account | Purpose | Access Pattern |
|---|
| BUILD | CI/CD pipelines, artifact generation, supply chain security | Isolated account. Other accounts can access readonly/immutable. |
| DEV | Active development and testing | Can access BUILD artifacts (readonly). |
| STAGING | Pre-production testing and validation | Can access BUILD artifacts (readonly). |
| PROD | Production workloads | Can access BUILD artifacts (readonly). |
BUILD Account Principles
CRITICAL: The BUILD account MUST be its own isolated AWS account.
- Isolation: BUILD account is completely separate from application environments
- Readonly Access: DEV, STAGING, and PROD can only read from BUILD (never write)
- Immutable Artifacts: Once built in BUILD, artifacts cannot be modified
- Supply Chain Security: All dependencies and builds happen in isolated BUILD environment
- Access Control: BUILD account has read/write. Other accounts have readonly only.
CodeArtifact Access Patterns
{
...buildEnv,
codeArtifact: {
codeArtifactDomainName: 'cdk-constructs',
codeArtifactRepositoryName: 'cdk-constructs-library-build',
codeArtifactRepositoryDescription: 'Build Repository - Supply Chain Security',
allowedAccounts: [Account.BUILD, Account.DEV, Account.STAGING, Account.PROD],
},
}
{
...devEnv,
codeArtifact: {
allowedAccounts: [Account.DEV, Account.STAGING, Account.BUILD],
},
}
Environment Configuration Location
Environment configurations follow CDK conventions:
- Types:
lib/types/project.ts - ProjectEnvironment type
- Configs:
lib/config/environments.ts - buildEnv, devEnv, stagingEnv, prodEnv
- Re-exports:
bin/environment.ts - Backwards compatibility
This follows the pattern: bin/ → lib/ for CDK applications.
Deployment Security
- Never deploy BUILD artifacts to BUILD account - BUILD creates, others consume
- Enforce readonly - Use IAM policies to prevent write access from non-BUILD accounts
- Tag everything - Environment and Owner tags applied automatically via EnvironmentConfig
- Audit access - Monitor cross-account access to BUILD artifacts
Common Build Issues
Issue: "Cannot find module '@cdk-constructs/...'"
Solution:
- Run
make install to set up workspace links
- Run
make build-all to build packages in order
- Ensure package is listed in
tsconfig.build.json
Issue: Circular dependency detected
Solution:
- Check package dependencies in
package.json
- Verify build order in
tsconfig.build.json
- Ensure no package depends on a package that depends on it