This is an example of containerized AWS CDK following the 3 Musketeers pattern.
What Is This 3 Musketeers Thing Anyway and Why Would I Want to Do Such a Thing as to Containerize the AWS CDK?
- 3 Musketeers for an epic Developer Experience
- What is 3 Musketeers?
- What is AWS CDK
There are a host of benefits to the 3 Musketeers pattern, which mostly center around Developer Experience. 3 Musketeers packages all the dependencies up into one container, making it easy for the whole team to stay up-to-date. The other substantial benefit I see of the 3 Musketeers pattern is just how darn easy it makes it to set up new developers. Simply make sure they install docker, docker-compose, and make (also WSL on Windows). Now setup for new projects is as simple as cloning down the repo and running make install.
If you’ve worked on any number of CDK projects, you’ve probably run into hiccups with dependency management, and you know how difficult these issues can be to fight through, especially for developers new to Node. It should be obvious now how 3 Musketeers can mitigate these.
Now that we’ve seen why it’s a good idea to use the 3 Musketeers pattern with the AWS CDK, let’s jump right into it.
Start by cloning down this repo from GitHub: https://github.com/chrishart0/aws-cdk-typescript-3-musketeers
This will have everything you need to try out containerized AWS CDK. Let’s go through the contents of this repo first.
Notice that the infrastructure directory is the output of running the command cdk init sample-app — language typescript. This gives us a basic sample app to work with. If you aren’t familiar with the AWS CDK in typescript, the infrastructure/lib/infrastructure-stack.ts file is where the infrastructure to be deployed is located. You will notice an SQS queue and an SNS topic have been defined with the queue subscribed to the SNS topic.
You can use this repo as is or replace the contents of infrastructure with your work.
Note: You don’t need an AWS account setup to test this locally, simply skip running the bootstrap command
Open up the CLI into the root of the repo you’ve cloned down locally.
Run the command make; this will do all the needed setup and run cdk synth from within the docker container.
If you have never used AWS CDK in your configured AWS account before then you must run the CDK bootstrapper. If you simply want to test this repo out locally you can skip this step.
$ make bootstrap
You are now free to run any other commands available such as
cdk deploy, and
If you have an existing project and would like to use this 3 Musketeers pattern then follow these steps:
- Copy the
docker-compose.yamlfiles into the root of your project
- Update the
- Run make to do initial setup and output cdk synth to verify everything is configured right For more information refer to the README on the GitHub repo. I’d love to hear any thoughts, comments, or critiques in the comments below.