Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/okruti-raghuraj/aws-1/llms.txt

Use this file to discover all available pages before exploring further.

AWS CDK (Cloud Development Kit) brings the full power of a programming language to infrastructure provisioning. Instead of writing raw CloudFormation YAML, you write TypeScript classes and functions that compile down to CloudFormation templates. CDK Pipelines, a higher-level construct built on top of CDK, takes that one step further by letting the pipeline manage and update itself every time you push a change.

What is the AWS CDK?

The AWS CDK is an open-source framework that lets you model AWS infrastructure as code using familiar programming languages — TypeScript, Python, Java, Go, and more. You write constructs (classes) that represent AWS resources; when you run cdk synth, the CDK synthesizes those constructs into a CloudFormation template that AWS can deploy. This project uses aws-cdk-lib 2.20.0, the CDK v2 monolithic library that ships every AWS service construct in a single package. CDK v2 replaces the per-service packages of CDK v1 (e.g. the legacy @aws-cdk/core and @aws-cdk/aws-lambda packages visible in package.json are CDK v1 remnants no longer needed).
# Install dependencies (includes aws-cdk-lib 2.20.0 and the cdk CLI)
npm ci

# Compile TypeScript to JavaScript
npm run build

# Synthesize CloudFormation templates to cdk.out/
npx cdk synth

What is CDK Pipelines?

CDK Pipelines is a high-level construct library shipped as part of aws-cdk-lib/pipelines. It wraps AWS CodePipeline to give you a self-mutating pipeline — a pipeline that can update its own infrastructure definition on every push without any manual cdk deploy step. The self-mutation loop works like this:
  1. Push — a developer pushes a commit to the watched GitHub branch.
  2. Source — CodePipeline detects the change and pulls the new source.
  3. Synth — the pipeline runs cdk synth to produce fresh CloudFormation templates.
  4. Self-mutation — CDK Pipelines compares the newly synthesized pipeline definition against the currently deployed one. If they differ, it updates the pipeline itself first.
  5. Deploy — once the pipeline is up to date, it deploys all application stages in order.
This means the pipeline is always in sync with the code that defines it. Adding a new deployment stage, changing an environment variable, or rotating a secret is as simple as editing a TypeScript file and pushing.

Key Constructs

ConstructModulePurpose
CodePipelineaws-cdk-lib/pipelinesTop-level construct that creates and manages the CodePipeline pipeline, including the self-mutation stage
CodePipelineSourceaws-cdk-lib/pipelinesStatic factory for pipeline source actions — GitHub, CodeCommit, S3, ECR, etc.
ShellStepaws-cdk-lib/pipelinesRuns arbitrary shell commands inside a CodeBuild project; used here for the Synth step
cdk.Stackaws-cdk-libA unit of deployment — maps 1:1 to a CloudFormation stack; all resources are defined inside a Stack
cdk.Stageaws-cdk-libA group of one or more stacks that are deployed together as a logical application environment (e.g. staging, production)
cdk.Appaws-cdk-libThe root of the CDK construct tree; app.synth() triggers synthesis of all stacks

CDK Context Flags

The cdk.json file at the project root configures the CDK CLI and sets feature flags via the context object. Feature flags let the CDK team ship safer defaults for new projects without breaking existing ones.
{
  "app": "npx ts-node --prefer-ts-exts bin/aws-cdk-pipeline.ts",
  "watch": {
    "include": ["**"],
    "exclude": [
      "README.md",
      "cdk*.json",
      "**/*.d.ts",
      "**/*.js",
      "tsconfig.json",
      "package*.json",
      "yarn.lock",
      "node_modules",
      "test"
    ]
  },
  "context": {
    "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
    "@aws-cdk/core:stackRelativeExports": true,
    "@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
    "@aws-cdk/aws-lambda:recognizeVersionProps": true,
    "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
    "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
    "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
    "@aws-cdk/aws-iam:minimizePolicies": true,
    "@aws-cdk/core:target-partitions": ["aws", "aws-cn"]
  }
}
Each true flag opts the project into a recommended behaviour change. Some notable ones:
  • @aws-cdk/aws-iam:minimizePolicies — consolidates IAM policy statements where possible, keeping generated policies lean.
  • @aws-cdk/aws-lambda:recognizeVersionProps — ensures Lambda version hashes change when configuration properties change, so new versions are published correctly.
  • @aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021 — enforces TLS 1.2 (2021) as the minimum security policy on new CloudFront distributions.
  • @aws-cdk/core:target-partitions — limits synthesized ARNs to the aws and aws-cn partitions, preventing accidental deployment to GovCloud unless explicitly requested.
The app field tells the CDK CLI how to execute the entry point. Here it uses ts-node --prefer-ts-exts so TypeScript source is run directly without a prior compile step during cdk synth and cdk deploy.

TypeScript Compilation

The project uses the TypeScript compiler (tsc) configured by tsconfig.json. The compiler targets ES2018 ("target": "ES2018") and emits CommonJS modules ("module": "commonjs"), which is the standard setup for Node.js-based CDK applications. Three workflows are available:
# One-shot compile: transpiles all .ts files to .js in the same directory tree
npm run build        # runs: tsc

# Incremental watch mode: recompiles automatically on every file save
npm run watch        # runs: tsc -w

# Execute TypeScript directly (used by the CDK CLI internally via cdk.json "app")
npx ts-node --prefer-ts-exts bin/aws-cdk-pipeline.ts
During active development, run npm run watch in a terminal tab so the compiled output is always up to date. The CDK CLI (cdk synth, cdk diff, cdk deploy) reads the compiled .js files when ts-node is not used directly.
When the CDK CLI synthesizes the app it invokes the command specified in cdk.jsonnpx ts-node --prefer-ts-exts bin/aws-cdk-pipeline.ts — which bypasses the compiled .js files entirely and runs TypeScript source directly. This is the standard CDK v2 setup.

Build docs developers (and LLMs) love