CDK Pipelines
CDK constructs for AWS CodePipeline setups that deploy a CDK app across multiple stages, accounts and regions.
npm install @ttskp/cdk-pipelines
Quick start
import { Stack } from 'aws-cdk-lib';
import { CodePipelineSource } from 'aws-cdk-lib/pipelines';
import {
AdditionalTrigger,
CleanupStacksMixin,
DeploymentTargetsSource,
MultiDeployCodePipeline,
SynthProfiles,
} from '@ttskp/cdk-pipelines';
new MultiDeployCodePipeline(pipelineScope, 'MultiDeployCodePipeline', {
synth: SynthProfiles.projenCdkApp(CodePipelineSource.gitHub('my-org/my-repo', 'main')),
stackFactory: { create: (scope, env) => new MyAppStack(scope, 'my-app', { env }) },
deploymentStages: [
{
name: 'dev',
targets: DeploymentTargetsSource.staticValue([{ account: '111111111111', region: 'eu-west-1' }]),
},
{
name: 'prod',
targets: DeploymentTargetsSource.ssmParameter('/pipelines/stages/prod'),
requireManualApproval: true,
},
],
mixins: [
AdditionalTrigger.ssmParameterChange('/pipelines/stages/prod'),
new CleanupStacksMixin(),
],
});
MultiDeployCodePipeline
A CodePipeline that deploys the same stack to many accounts and regions, one wave per deployment stage.
Deployment stages
Each entry in deploymentStages becomes a wave named Deploy-<name>. A stage has:
| Property |
Description |
name |
Stage name. |
targets |
Where to deploy, see Deployment targets. |
stackFactory |
Creates the stack to deploy. |
requireManualApproval |
Adds a manual approval step before the wave. |
pre / post |
Extra steps before or after the wave. |
Stages whose targets resolve to an empty list are skipped.
Deployment targets
DeploymentTargetsSource provides the list of { account, region, name? } targets for a stage:
staticValue(targets): targets defined in code.
ssmParameter(name): targets read from an SSM parameter at synth time. The value must be a JSON array of targets. Before the first context lookup has run, it resolves to no targets.
Implement IDeploymentTargetsProvider for other sources.
Mixins
Mixins hook into pipeline creation through the mixins property. Extend CodePipelineMixin to write your own.
| Mixin |
Description |
AdditionalTrigger.ssmParameterChange(...names) |
Starts the pipeline when one of the SSM parameters is created, updated or labeled. |
AdditionalTrigger.schedule(schedule) |
Starts the pipeline on an EventBridge schedule. |
CleanupStacksMixin(skipDeletion?, qualifier?) |
Deletes deployed stacks in target accounts when the pipeline stack no longer deploys them, e.g. a target was removed. Assumes the CDK deploy role for the given bootstrap qualifier. Set skipDeletion to keep stacks. MultiDeployCodePipeline only. |
Synth profiles
SynthProfiles.projenCdkApp(input) returns a ready-made synth step for projen-based CDK apps (yarn install, npx projen, npx cdk synth).
API reference
See API.md.
License
Licensed under the Apache License 2.0.
评论