Amazon AWS has been quite busy, enabling a better developer experience in its products. With tools like Cloud9, which enables you to edit code directly in the comfort of your browser to the Amazon AWS Cloud Developer Kit or better known as CDK.
Amazon CDK was first announced at AWS Summit in New York back in 2019. The announcement fell through the cracks due to the overwhelming number of daily service/feature releases. However, CDK itself is quite amazing and is definitely on to something regards to bringing a better developer/DevOps experience to its users to bring the roles even closer together.
What is AWS CDK
What is CDK, and what's so good about it? CDK is approaching infrastructure with developers in mind (finally). Now, developers can deploy AWS infrastructure directly inside their favorite programming language. For example, using Python, we can deploy and manage AWS infrastructure with just a couple lines of Python code. Wait; what?!?!
Yes, it was hard to grasp at first, but I like the concept. Instead of context switching to a different tool to deploy infrastructure, I can stay in my programming language comfort zone and deploy infrastructure inline with my application. Has your mind blown yet?
How does CDK work?
CDK contains preconfigured application components called Constructs. CDK has a Construct Library, which is a collection of bootstrap templates, including the logic for one or more AWS services/features. It is easy to download, customize, and deploy Constructs like S3, SQS, ECS, RDS, and many more all within the same programming language and IDE like Visual Studio Code. The new workflow reduces context switching and streamlines the developer experience. For example, we can quickly provision an ECS cluster combined with our application in just a few lines of Python code.
Behind the scenes, CDK is creating CloudFormation templates based on AWS best practices. The CloudFormation templates are then available to edit after the initial deployment. The creation of the CloudFormation templates is a bit of the magic that CDK is performing. The downside is we don't know how CDK creates these templates or if they follow best practices until we deploy.
Is CDK just a CloudFormation/Terraform replacement?
Short answer: no. You should be seeing CDK as an add-on to CloudFormation. It is an extra tool for when you need all the power of a full-fledged programming language.
Both CloudFormation and Terraform are DSLs, which offer a limited set of ways you can manage your infrastructure. They are "highly opinionated", in the sense that certain tasks can only be achieved in certain ways, their way.
This means that most use cases are covered by their DSL, but if you find yourself either not being able to achieve your infrastructure goals or not liking the way CloudFormation or Terraform "make" you achieve them, CDK might be the right choice.
One other possible use case could be if your team is already using one programming language and doesn't have the time or resources to learn something new, like CloudFormation or Terraform. CDK would make it easier to get into infrastructure-as-code by providing a more moderate learning curve.
What are the challenges when using CDK?
CDK's greatest strength - flexibility - comes bundled with its biggest challenge: complexity.
A very narrow focused DSL like Terraform is easier to learn and use than a programming language. A language that will have its own set of peculiarities that one has to be familiar with and that will have to be "bent" to the specific use cases of infrastructure deployment.
CDK also adds another layer to your stack, because it generates CloudFormation templates. When debugging, you might end up looking not only into the CDK stacks you have written, but also in the CloudFormation stacks that have been generated and applied. As usual, more complexity, more chances of something breaking and more to debug.
AWS CDK Summary
To summarize AWS CDK, it is an excellent concept and super easy to get started deploying AWS infrastructure. We find that it is a perfect tool for people (Engineers, Developers, Operations) starting with the AWS ecosystem or already comfortable with one of the CDK supported programming languages; Typescript, Python, .Net, or Java.
Some of the drawbacks we pointed out earlier in the article, which Dan Achim so eloquently put it "CDK's greatest strength - flexibility - comes bundled with its biggest challenge: complexity."
CDK is not a tool for everyone, and for more advanced infrastructure engineers, a bit too much "magic" is happening behind the scenes. Typically, as an engineer, it is essential to understand all the mechanics of what you are deploying. At the same time, I would recommend it to developers or people starting with AWS.
Where CDK shines is the fact that it is embracing so much Open Source mentality and publishing constructs and open source examples. CDK is headed in the right direction. It is still relatively new but needs more community behind it to drive adoption and an ecosystem around CDK. We will be watching CDK closely.
Initially, we thought of creating some samples of CDK in action. However, after some research, we discovered some great resources to help get started.
First up is the CDK workshop which AWS created. It is intuitive and covers Typescript, Python, .Net, and Java workshops. The workshop covers setting up projects, navigating CDK commands, and deploying projects.
CDK Workshop - https://cdkworkshop.com/
Next, is the AWS CDK Examples GitHub repo. Another great resource with examples from deploying S3 buckets to ECS clusters in your Programming language of choice.
AWS CDK Example GitHub Repo - https://github.com/aws-samples/aws-cdk-examples
Find out more about 56K.Cloud
We love Cloud, IoT, Containers, DevOps, and Infrastructure as Code. If you are interested in chatting connect with us on Twitter or drop us an email: info@56K.Cloud We hope you found this article helpful. If there is anything you would like to contribute or you have questions, please let us know!