TLDR; Yes, you can shorten cdk development cycles. Keep your pipeline for prod deploys. For development, deploy a copy of the app to a "sandbox" account using the cdk-cli
. This sandbox non-pipeline app deploys faster to the cloud and works with the local lambda sam testing you mention.
Deploy #1: Pipeline for Prod Deploys As it seems you do, we deploy to our production account via a CDK pipeline setup. The pipeline runs in a test account.
The pipeline's cdk.Stage
calls a makeAppStacks
function, which encapsulates our stack definitions. The function makes a second appearance below in Deploy #2 when we define our non-pipeline sandbox app. We write the stack code once, but deploy it as a pipeline and standalone app.
// DeployStage.ts
// The stage gets added to the pipeline for deploys to test, prod etc.
export class DeployStage extends cdk.Stage {
constructor(scope: cdk.Construct, id: string, props: DeployStageProps) {
super(scope, id, props);
// actually adds the stack constructs to the app
makeAppStacks(
this,
props.appName,
props.env.account,
props.env.region,
);
}
}
Deploy #2: cdk deploy
to a Sandbox Account for Iterative Development. As you say, the pipeline deploy is too slow for iterative development - you don't want to wait 15 minutes for CodePipeline to pull from the repo, build and deploy for every minor change in a feature branch.
So for faster development, we deploy the same stacks to a sandbox account via CLI, which is faster to deploy to the cloud and can use the local sam debugging.
# deploy the app to a sandbox account for fast(er) iterations
# app.ts uses the AWS_ACCOUNT env var to dynamically deploy
AWS_ACCOUNT=123456789000 npx cdk deploy '*' -a 'node ./bin/app' --profile my-sandbox
// bin/app.ts
// called from the cli, deploys to the sandbox account
const app = new App();
const account = process.env.AWS_ACCOUNT;
// reused stack definitions!
makeAppStacks(app, 'UnicornApp', account, 'us-east-1');