Bootstrapping AWS CDK Automation With Amazon CodeCatalyst
A step-by-step on establishing an AWS CDK setup alongside Amazon CodeCatalyst, enabling the creation of a comprehensive CI/CD pipeline for your infrastructure.
Published Jan 24, 2024
Last Modified Jul 24, 2024
A step-by-step guide on establishing an AWS CDK setup alongside Amazon CodeCatalyst from the ground up, enabling the creation of a comprehensive CI/CD pipeline for your infrastructure.
AWS CDK is fantastic for overseeing your entire infrastructure as code, but when multiple developers are involved in modifying the infrastructure, the situation can become chaotic without a proper mechanism like a CI/CD pipeline. Absence of such a system makes coordinating and communicating changes to the infrastructure a challenging task, and this challenge amplifies as more individuals participate in the modification process.
This tutorial will guide you through setting up a CI/CD pipeline using Amazon CodeCatalyst and AWS CDK for building To-Do web application
Source code: Github
- Login to CodeCatalyst and go to your Space (Create one if you don't have)
- Create a project from scratch
- Create repository to store code and workflows of the project
- Create CICD
Environments
which associates to AWS account for deploying our infrastructure - Create IAM role for codecatalyst to consume during running workflows. It should be already created while you create the Space or you can customize the others
Workflows directory
Workflows is triggered by
PUSH
of branch main
and includes following Actions
FrontendBuildAndPackage
- Build react app, target build
which is shared to cross-actions by Artifacts
of Outputs
FrontendTest
Test frontend codeCDKBootstrapAction
- Run cdk bootstrap
for the region of the account with latest CDK version. This action depends on FrontendTest
and FrontendBuildAndPackage
CDKDeploy
- Download build target of FrontendBuildAndPackage
and trigger cdk deploy
, this action depends on CDKBootstrapAction
. Here I don't use the defined action aws/cdk-deploy@v1
of CodeCatalyst because I'd like to use projen
and pnmp
in CDK and handle copying frontend target buildUse EC2 compute type for CodeCatalyst workflows
cdkStack
Define CDK stacks and useprojen
for configuration management as well aspnpm
frontend
Frontend react app
Init the repo and add repo URL which is created from the above as
origin
When the commit is pushed to the
main
branch, CodeCatalyst CI/CD triggers the workflowsThe
CDKDeploy
triggers cloudformation to create AWS resourcesAfter the workflows done, we now have the To-Do Web app UI
Congratulations! You've successfully bootstrapped and initialized AWS CDK with CodeCatalyst, and you can now deploy infrastructure changes or update frontend/backend using a pull request workflow.