This is a CDK stack designed to help you create a CDK app using a CICD pipeline. For those who just want to get to it the directions are under Walkthrough. If you are unsure of anything check the Prerequisite
If you're playing around with the CDK alot, you’ll want to have a solid starting point. This guide acts as starting point that can be where you kick off from!
There is a lot of information out there about the CDK. Official workshops, one off guides, blogposts, and they all show great stuff. When learning any new technology or framework practice makes perfect and what better way to practice then the iteration of building, deploying, breaking, and eventually success! That’s where this guide hopes to help. It provides an approach to learning the CDK that aims to be the base for any future CDK material you consume.
In the spirt of true iteration this guide recommends you use some sort of containerized dev environment so that if you install or uninstall the wrong packages its no big deal and you can just get rid of that environment. Not sure how to do this? Here’s an example of how to create a dev container with Visual studio code
The AWS Cloud Development Kit (AWS CDK) is an open source framework that allows you to deploy AWS infrastructure as code. Here are a few links with background information if you want to know more
- Have an AWS Account and Github Account
- Install the AWS Cli
- Create programmatic credentials and configure them
- Check out the Where to build section and install the AWS CDK
-
Step one is to do a local clone of this repository
git clone https://github.com/QuinnPipeline/pipeline_kickoff.git
-
Create a github repo on github
- You should create two *One for the pipeline kickoff (recommended that this repo is private) *One for your new CDK app (recommended that this repo is private)
-
Delete the local .git and .gitignore folders in your cloned repo of pipeline_kickoff
-
Run the following commands in your local clone of pipeline_kickoff to make it your own
git init
git branch -M main
git add -A .
git commit -m "first commit"
git remote add origin git@github.com:<your_git_user_name>/pipeline_kickoff
git push -u origin master
-
Edit the pipeline_kickoff/bin/pipeline_kickoff.ts *You will have to put in your account number and pick the region you want you deploy to
-
And pipeline_kickoff/bin/pipeline_kickoff.ts *Edit line 10 and add your github source info
const git_source = ' ' //'OWNER/REPO' format
-
You'll also need to create a github token with the repo and admin:repo_hook permissions and store it as a plaintext secret under the name github-token.
-
Run
npx cdk synth
andnpm run build
to check for errors and see if you are missing packages *install packages vianpm install '@aws-cdk/<package_name>'
*If you're getting any package version errors try updateing all your packages to the current version -
Bootstrap your CDK environment so you can deploy the pipeline kickoff
- You have to bootstrap for ever region you deploy into
npx cdk bootstrap aws://ACCOUNT-NUMBER-1/REGION-1 aws://ACCOUNT-NUMBER-2/REGION-2 ...
- You have to bootstrap for ever region you deploy into
-
One final commit now that your pipeline is fully configured
git add -A .
git commit -m "final commit"
git push
You now have an example of an empty pipeline. You can deploy it withnpx cdk deploy
to see how it works in The CodePipeline Console
- Navigate into your other local repo
- Create your own CDK app.
npx CDK init app --language=typescript
- Add the following to the CDK.json file
"@aws-cdk/core:newStyleStackSynthesis": true
- This will allow your app to use the new bootstrapping method
- Take a look at your pipeline kickoff project
- Pay attention to a few things about the layout of the files and folder structure
- You'll notice a clear line of reference for how the files interact with each other. If you look inside each file you'll see this reference expressed via the import function.
- You can use this layout as a reference while writing your own app
- Compare your new apps layout to the pipeline_kickoff layout
- You can see how to start your build from there, more prescriptive guidance to come!
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testsnpx CDK deploy
deploy this stack to your default AWS account/regionnpx CDK diff
compare deployed stack with current statenpx CDK synth
emits the synthesized CloudFormation templatenpx CDK init <options>
best way to start a new project