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.

This guide walks you through everything needed to deploy a self-mutating CI/CD pipeline to your AWS account using the AWS CDK Pipeline project. By the end you will have a running AWS CodePipeline that watches a GitHub repository and automatically updates itself whenever you push changes to your CDK infrastructure code.
The bin/aws-cdk-pipeline.ts entry point currently hardcodes account 602143770054 and region ap-south-1. You must replace these values with your own AWS account ID and target region before running cdk deploy, otherwise the deployment will fail or provision resources into the wrong account.
1

Install prerequisites

Make sure the following tools are installed and available on your PATH before continuing:
npm install -g aws-cdk@2.20.0
Verify everything is in place:
node --version      # v14.x or later
aws --version       # aws-cli/2.x
cdk --version       # 2.20.0
2

Clone the repository

Clone the monorepo and navigate into the CDK pipeline project directory:
git clone https://github.com/okruti-raghuraj/aws-1.git
cd aws-1/aws-pipeline/aws-cdk-pipeline
3

Install dependencies

Install all Node.js dependencies declared in package.json:
npm install
The key runtime dependencies that will be installed are:
{
  "dependencies": {
    "aws-cdk-lib": "2.20.0",
    "constructs": "^10.0.0",
    "source-map-support": "^0.5.16",
    "@aws-cdk/aws-lambda": "^1.153.1",
    "@aws-cdk/core": "^1.152.0"
  }
}
4

Configure GitHub source

Open lib/aws-cdk-pipeline-stack.ts and update the CodePipelineSource.gitHub() call to point at your own GitHub repository and branch:
const pipeline = new CodePipeline(this, 'Pipeline', {
  pipelineName: 'TestPipeline',
  crossAccountKeys: false,
  synth: new ShellStep('synth', {
    // Replace 'YourOrg/YourRepo' and 'your-branch' with your own values
    input: CodePipelineSource.gitHub('YourOrg/YourRepo', 'your-branch'),
    commands: [
      'npm ci',
      'npm run build',
      'npx cdk synth'
    ]
  }),
});
The original source points to CodePipelineSource.gitHub('RaghurajSingh/SMS', 'aws-pipeline'). Change both the repository (owner/repo) and the branch name to match your setup.CDK Pipelines uses a GitHub connection managed by AWS CodeStar Connections under the hood. The first time you deploy, AWS will prompt you to authorise the connection in the AWS console.
5

Set your AWS environment

Open bin/aws-cdk-pipeline.ts and replace the hardcoded account and region with your own values:
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import { AwsCdkPipelineStack } from '../lib/aws-cdk-pipeline-stack';

const app = new cdk.App();
new AwsCdkPipelineStack(app, 'AwsCdkPipelineStack', {
  // Replace with your actual AWS account ID and preferred region
  env: { account: 'YOUR_ACCOUNT_ID', region: 'YOUR_REGION' },
});
app.synth();
Alternatively, use environment variables so the file does not contain a hardcoded account ID:
env: {
  account: process.env.CDK_DEFAULT_ACCOUNT,
  region: process.env.CDK_DEFAULT_REGION,
},
6

Bootstrap CDK

CDK bootstrapping provisions the S3 bucket, ECR repository, and IAM roles that CDK needs to deploy stacks into your account and region. Run this once per account/region combination:
cdk bootstrap aws://YOUR_ACCOUNT_ID/YOUR_REGION
For example:
cdk bootstrap aws://123456789012/us-east-1
7

Build and deploy

Compile the TypeScript source and deploy the pipeline stack to AWS:
npm run build && cdk deploy
CDK will display a summary of the IAM and resource changes it intends to make. Confirm when prompted. The initial deployment typically takes 2–5 minutes.

What happens after deploy

Once cdk deploy completes, AWS CodePipeline takes over:
  1. Pipeline is created in the CodePipeline console under the name TestPipeline.
  2. First execution starts immediately — it clones your GitHub repository, runs the synth step (npm ci, npm run build, npx cdk synth), and self-mutates the pipeline stack if needed.
  3. Every subsequent push to your configured branch triggers a new pipeline execution, which again self-mutates before deploying any application stages you have added.
You can monitor progress in the AWS CodePipeline console.

Available npm scripts

The following scripts are defined in package.json for day-to-day development:
npm run build   # Compile TypeScript to JavaScript (tsc)
npm run watch   # Watch for changes and recompile automatically (tsc -w)
npm run test    # Run Jest unit tests
npm run cdk     # Run the CDK CLI (equivalent to npx cdk)
Before running cdk deploy, run cdk diff to preview exactly which CloudFormation resources will be created, modified, or deleted. This is especially useful when iterating on your pipeline or application stack definitions:
cdk diff

Build docs developers (and LLMs) love