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.

The CDK application ships with default values pointing to a specific AWS account, region, and GitHub repository. Before you deploy, you need to update these values to match your own environment. All configuration lives in two files: bin/aws-cdk-pipeline.ts (environment targeting) and lib/aws-cdk-pipeline-stack.ts (pipeline definition).

Environment Configuration

The entry point file bin/aws-cdk-pipeline.ts instantiates the CDK app and passes environment details to the stack. Here is the full source as it exists in the project:
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
//import * as cdk from '@aws-cdk/core';
import { AwsCdkPipelineStack } from '../lib/aws-cdk-pipeline-stack';

const app = new cdk.App();
new AwsCdkPipelineStack(app, 'AwsCdkPipelineStack', {
  /* If you don't specify 'env', this stack will be environment-agnostic.
   * Account/Region-dependent features and context lookups will not work,
   * but a single synthesized template can be deployed anywhere. */

  /* Uncomment the next line to specialize this stack for the AWS Account
   * and Region that are implied by the current CLI configuration. */
  // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },

  /* Uncomment the next line if you know exactly what Account and Region you
   * want to deploy the stack to. */
  env: { account: '602143770054', region: 'ap-south-1' },

  /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */
});
app.synth();
The env block pins the stack to a specific AWS account and region:
  • account — the 12-digit AWS account ID where the pipeline and all its resources will be created. Replace '602143770054' with your own account ID.
  • region — the AWS region code (e.g. 'ap-south-1' for Mumbai). Replace this with your preferred region such as 'us-east-1' or 'eu-west-1'.
If you remove the env property entirely, the stack becomes environment-agnostic — it can be synthesized and deployed anywhere, but features that require a known account or region (such as certain context lookups and cross-region references) will not work.
Instead of hardcoding account and region, you can use CDK environment variables to inherit the values from your current AWS CLI profile. This makes the project portable across team members without editing source files:
env: {
  account: process.env.CDK_DEFAULT_ACCOUNT,
  region: process.env.CDK_DEFAULT_REGION,
},
CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION are automatically set by the CDK CLI based on the active AWS credentials and profile.

GitHub Source Configuration

The pipeline stack (lib/aws-cdk-pipeline-stack.ts) defines the pipeline and its source:
import * as cdk from 'aws-cdk-lib';
//import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CodePipeline ,  CodePipelineSource , ShellStep } from 'aws-cdk-lib/pipelines';
// import * as sqs from 'aws-cdk-lib/aws-sqs';

export class AwsCdkPipelineStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // The code that defines your stack goes here

    const pipeline = new CodePipeline(this , 'Pipeline' ,{
      pipelineName: 'TestPipeline',
      crossAccountKeys: false,
      synth: new ShellStep('synth' , {
        input: CodePipelineSource.gitHub('RaghurajSingh/SMS','aws-pipeline'),
        commands:['npm ci' ,
                  'npm run build',
                  'npx cdk synth']
      }),
    });
    // example resource
    // const queue = new sqs.Queue(this, 'AwsCdkPipelineQueue', {
    //   visibilityTimeout: cdk.Duration.seconds(300)
    // });
  }
}
The source is configured with CodePipelineSource.gitHub('RaghurajSingh/SMS', 'aws-pipeline'):
  • The first argument ('RaghurajSingh/SMS') is the GitHub repository in owner/repo format. Replace this with your own GitHub repository, e.g. 'myorg/my-cdk-app'.
  • The second argument ('aws-pipeline') is the branch name the pipeline watches for commits. Change this to whatever branch you want to trigger pipeline runs, e.g. 'main' or 'production'.

Pipeline Name

The pipeline is named 'TestPipeline' via the pipelineName property. This is the name that appears in the AWS CodePipeline console. Update it to something meaningful for your project:
pipelineName: 'MyApplicationPipeline',
Pipeline names must be unique within a region and account, and they cannot be changed after the pipeline is created without destroying and recreating the stack.

Cross-Account Keys Setting

The crossAccountKeys: false option controls artifact encryption:
  • false (default here) — pipeline artifacts stored in S3 are encrypted with SSE-S3 (Amazon-managed keys). This is simpler and incurs no extra cost. Use this when all pipeline stages deploy to the same AWS account.
  • true — artifacts are encrypted with AWS KMS customer-managed keys (CMK). This is required when the pipeline deploys to a different AWS account (cross-account deployments), because S3-managed keys cannot be shared across account boundaries.
Since this pipeline targets a single account, crossAccountKeys: false is the correct choice.

Synth Commands

The ShellStep runs three commands inside the CodeBuild project to produce the CDK cloud assembly:
CommandPurpose
npm ciClean install of all dependencies from the lock file — reproducible and faster than npm install
npm run buildCompiles TypeScript source to JavaScript via tsc — required because CDK reads .js files at runtime
npx cdk synthSynthesizes all stacks into CloudFormation templates inside cdk.out/ — the pipeline reads these templates to determine what to deploy
These three commands mirror the manual workflow you would run locally. If you add additional build or test steps to your project, add them here before npx cdk synth.

CDK Context

The cdk.json file at the project root holds feature flags under the context key. These flags opt in to specific CDK behaviours such as lowercase RDS identifiers, minimized IAM policies, and TLS 1.2 enforcement for CloudFront. They are already set to the recommended values for CDK v2.20.0. See CDK Overview for a detailed explanation of each flag.

Build docs developers (and LLMs) love