This repository use CDK Pipelines to implement CI/CD for CDK Application.
Split relevent AWS Service into same directory, such as Network, Ecs etc... See below:
project
│ README.md
│ config.yml
│
└───src
│ │ main.ts
│ │
│ └───network
│ │ cdk-pipelines.ts
│ │ network-stage.ts
│ │ network-stack.ts
│ │ ...
│ └─── configs
│ │ dev.yml
│ │ prod.yml
│ └───ecs
│ │ cdk-pipelines.ts
│ │ ecs-stage.ts
│ │ ecs-stack.ts
│ │ ...
│ └─── configs
│ │ dev.yml
│ │ prod.yml
When CDK Pipelines cross different account or region for deployment, validate CloudFormation template first which is good way. The benefit is risk reduction that it ensure any modification which be reviewd. The code snippet like blow:
const ecsWave = pipeline.addWave('Ecs');
ecsWave.addStage(
new EcsStage(this, 'Dev', {
env: { account: props.devAccount, region: 'ap-northeast-1' },
stageEnv: 'dev',
}),
{
pre: [new pipelines.ShellStep('Validate dev CloudFormation Synth', {
commands: [
'yarn install --frozen-lockfile',
'./node_modules/.bin/jest --passWithNoTests test/ecs-dev.test.ts',
],
})],
},
);
ecsWave.addStage(
new EcsStage(this, 'Production', {
env: { account: props.prodAccount, region: 'ap-northeast-1' },
stageEnv: 'prod',
}),
{
pre: [new pipelines.ShellStep('Validate staging CloudFormation Synth', {
commands: [
'yarn install --frozen-lockfile',
'./node_modules/.bin/jest --passWithNoTests test/ecs-prod.test.ts',
],
})],
},
);It can use cliVersion prop to specify cdk version. Reference here
When modify code of stack, it's good way for using cdk diff to review what the modification. The command like below:
Network Dev
cdk synth -q && cdk diff -a cdk.out/assembly-TestNetwork-DevNetwork Production
cdk synth -q && cdk diff -a cdk.out/assembly-TestNetwork-Production ECS Dev
cdk synth -q && cdk diff -a cdk.out/assembly-TestEcs-DevTake test deployment further on local environment
cdk synth -q && cdk deploy -a cdk.out/assembly-TestEcs-Dev –no-rollback
The
–no-rollbackparameter is useful for test deployment for CloudFormation