Deploy Stack with the Pipeline
Now that we are satisfied with our DemoStack implementation in the Workbench, it’s time to deploy it through the pipeline.
Update the Pipeline to Include the DemoStack
This time, we will use the BaseStackProvider class, which helps maintain cleaner and more manageable code.
Step 1: Create the DemoProvider Class
We’ll begin by creating a bin/demo-provider.ts
file that will use the BaseStackProvider
class to provide the DemoStack.
- Create a file named
bin/demo-provider.ts
. - Add the following content to the file:
import * as wrapper from '@cdklabs/cdk-cicd-wrapper';
import { DemoStack } from '../lib/demo-stack';
export class DemoProvider extends wrapper.BaseStackProvider {
stacks(): void {
new DemoStack(this.scope, 'DemoStack', { env: this.env });
}
}
Congratulations! You’ve successfully created the
DemoProvider
class to manage the deployment of theDemoStack
.
Step 2: Add the DemoProvider to the Pipeline
Next, we will modify the bin/cdk-cicd-example.ts
file to include the DemoProvider.
- Open the
bin/cdk-cicd-example.ts
file. -
Add the following line to include the DemoProvider class:
3. Import the.addStack(new DemoProvider())
DemoProvider
class at the top of the file:import { DemoProvider } from './demo-provider';
Great work! You’ve successfully updated the pipeline to include the DemoProvider class.
Show Solution
The bin/cdk-cicd-example.ts
file should look like this:
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from 'aws-cdk-lib';
import * as wrapper from '@cdklabs/cdk-cicd-wrapper';
import { DemoStack } from '../lib/demo-stack';
import { DemoProvider } from './demo-provider';
const app = new cdk.App();
wrapper.PipelineBlueprint.builder()
.defineStages([
{ stage: wrapper.Stage.RES, account: process.env.AWS_ACCOUNT_ID },
{ stage: wrapper.Stage.DEV, account: process.env.AWS_ACCOUNT_ID },
])
.workbench({
provide(context) {
new DemoStack(context.scope, 'DemoStack', { env: context.environment });
},
})
.addStack(new DemoProvider())
.synth(app);
Step 3: Commit and Push the Changes
Let’s commit and push the changes to the repository so the pipeline can pick them up.
-
Run the following command to fix any linting issues:
npm run lint -- --fix
-
Add the changes to Git:
git add .
-
Commit the changes with a meaningful message:
git commit -m "feat: include DemoStack in CD"
-
Push the changes to the remote repository:
git push
Fantastic! Your changes have been committed and pushed to the repository.
Step 4: Monitor the Pipeline for Deployment
Once the changes are pushed, the pipeline will update, and a new DEV stage will appear for deploying the DemoStack.
- Go to the AWS CodePipeline service in the AWS Management Console.
- Select the
cdk-cicd-example
pipeline. - Monitor the progress of the pipeline. The UpdatePipeline step will update the pipeline configuration to include the new DEV stage.
You’ve successfully integrated the **DemoStack** into the pipeline.
Click Next to continue to the next section.