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.
MyPipelineAppStage is the deployment unit that the pipeline operates on. Rather than deploying individual stacks directly, CDK Pipelines works with cdk.Stage subclasses — each stage encapsulates one or more stacks that should always be deployed together. This abstraction is what makes it straightforward to promote the same set of stacks through dev, staging, and production environments without duplicating configuration.
What Is a CDK Stage?
Acdk.Stage is a scope that groups related stacks into a single deployable unit. When the pipeline executes, it treats each stage as an atomic wave: all stacks inside a stage are synthesized together, and the pipeline will not advance to the next stage until every stack in the current one has deployed successfully.
Key properties of a CDK stage:
- Atomic deployment — all stacks within a stage succeed or fail together as a group.
- Environment isolation — each stage can target a different
accountandregion, enabling cross-account pipelines. - Multiple stages per pipeline — you can chain dev → staging → prod stages in a single pipeline definition, each receiving the same set of stacks but deploying to different environments.
- Pre/post hooks — stages accept optional validation steps (integration tests, approval gates) that run before or after the stacks are deployed.
Current Implementation
The filelib/my-pipeline-app-stage.ts ships fully commented out, matching the same template approach used by LambdaStack. Activate it by uncommenting the file once you are ready to wire the application into the pipeline.
aws-cdk-pipeline/lib/my-pipeline-app-stage.ts
The commented-out file imports from
'./my-pipeline-lambda-stack' while the actual Lambda stack file is named aws-cdk-pipeline-lambda-stack.ts. Update the import path when you uncomment to match the real filename.Uncommented Implementation
After removing the comment markers and correcting the import, the stage looks like this:this (the stage) as the scope to LambdaStack registers the stack under the stage. CDK automatically namespaces the CloudFormation stack name as <StageId>-LambdaStack, so you can deploy the same stage to multiple environments without name collisions.
Adding a Stage to the Pipeline
OnceMyPipelineAppStage is active, attach it to the pipeline inside AwsCdkPipelineStack:
addStage appends the stage after the pipeline’s built-in self-mutation stage. The env passed here pins the stage to the same target account and region used in the app entry point, ensuring stacks land in the intended environment.
Multi-Environment Deployment
One of the primary reasons to usecdk.Stage is the ability to promote the same application across multiple environments by calling addStage multiple times with different env values:
Dev first and only promote to Prod if every stack in the Dev stage reaches CREATE_COMPLETE or UPDATE_COMPLETE. For cross-account deployments, make sure both the Dev and Prod accounts have been bootstrapped with cdk bootstrap --trust <PIPELINE_ACCOUNT_ID>.
Stage vs Stack — a stage represents an environment (dev, staging, production) and can contain many stacks. A stack represents a single service or component (a Lambda function, a database, an API Gateway). Use stages to separate environments; use stacks to separate concerns within an environment.