Why use CDK for infrastructure as code
In AWS you have a lot of ways to set up your infrastructure. Configuring it through the website is easy for trying out small stuff but difficult to migrate to other environments or to reproduce your steps. Using infrastructure as code, where you add scripts to your code repository that deploy your application, you can easily reproduce steps and reuse those steps to deploy to different environments. Considering I usually tend to forget after a while how I set things up exactly I favor the infrastructure as code.
You could run a series of commands through the AWS cli to create all the infrastructure you need and tie them together. I don't think this is maintainable and you might loose oversight quite quickly. I prefer using Cloudformation templates to describe the end state of the infrastructure. You just send the template to AWS and they will update your infrastructure (Stack) to the desired state. The feedback loop is quite long when you make a mistake in the Cloudformation template and reusing parts of a template is a lot of copy pasting. There might be better ways out there to use the templates but in the mean time CDK was released.
With CDK you can write your infrastructure in a programming language of your choice. They support quite some languages ( JavaScript, TypeScript, Python, Java, C#, and Go), which comes with the expected benefits of DRY support of packages and other things to make your life easier. CDK also helps you with setting some sensible defaults and gets you started quickly. You have more early checks on your infrastructure and it will stop you from making some common mistakes. This makes the feedback loop significantly faster. Also, CDK gives you intellisense for what information you have to provide to set up your infrastructure.
So this is why I'll use CDK, for the quick feedback loop, easy constructs and the easy reuse of code. Let's go look at how to set it up!
Don't worry the code examples are coming soon!
Thanks for reading
I enjoyed trying to make everything and I hope you'll enjoy reading it. If you are excited to have a chat or think I could improve feel free to write me on LinkedIn. I also have portfolio website where I put most of what I make and host trial projects portfolio.rohanengosia.com.