Skip to content

This is a CDK stack designed to help you create a CDK app using a CICD pipeline.

Notifications You must be signed in to change notification settings

QuinnPipeline/pipeline_kickoff

Repository files navigation

Welcome to your Cloud Development Kit (CDK) TypeScript project!

Kicked off with your very own CICD pipeline

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

Why use this repo?

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!

Introduction

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.

Where to build

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

Cloud Development Kit (CDK) background info

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

Prerequisite

Walkthrough

Empty pipeline
  1. Step one is to do a local clone of this repository git clone https://github.com/QuinnPipeline/pipeline_kickoff.git

  2. 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)
  3. Delete the local .git and .gitignore folders in your cloned repo of pipeline_kickoff

  4. 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
  5. 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

  6. And pipeline_kickoff/bin/pipeline_kickoff.ts *Edit line 10 and add your github source info const git_source = ' ' //'OWNER/REPO' format

  7. 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. PlaintextSecretExample

  8. Run npx cdk synth and npm run build to check for errors and see if you are missing packages *install packages via npm install '@aws-cdk/<package_name>' *If you're getting any package version errors try updateing all your packages to the current version

  9. 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 ...
  10. 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 with npx cdk deploy to see how it works in The CodePipeline Console
Customize your pipeline
  1. Navigate into your other local repo
  2. Create your own CDK app. npx CDK init app --language=typescript
  3. Add the following to the CDK.json file "@aws-cdk/core:newStyleStackSynthesis": true
    • This will allow your app to use the new bootstrapping method
  4. Take a look at your pipeline kickoff project
    • Pay attention to a few things about the layout of the files and folder structure filefolderlayoutpic
    • 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
  5. 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!

Useful commands

  • npm run build compile typescript to js
  • npm run watch watch for changes and compile
  • npm run test perform the jest unit tests
  • npx CDK deploy deploy this stack to your default AWS account/region
  • npx CDK diff compare deployed stack with current state
  • npx CDK synth emits the synthesized CloudFormation template
  • npx CDK init <options> best way to start a new project

About

This is a CDK stack designed to help you create a CDK app using a CICD pipeline.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published