Blog articles

What is AWS CDK and Why Should You Use It?

May 22, 2023

Never heard of AWS CKD? If you haven’t, I’m super excited to tell you, because this powerful tool can take your cloud infrastructure game to the next level and blow your whole world wide open (And now I’ve set a very high bar for this article to clear, so let’s continue).

What exactly is AWS CDK?

AWS CDK, or AWS Cloud Development Kit, is an open-source software development framework that lets you use modern programming languages to create cloud infrastructure. Instead of YAML or JSON for AWS CloudFormation, you get to use familiar, friendly things like TypeScript, Python, Java, and C#. 

That’s pretty cool, because devs can define their cloud infrastructure using code just like they’d write any other software application. That also means you can apply the same best practices used in software development, like managing and deploying cloud resources in a consistent, repeatable way. It also offers a higher-level, object-oriented abstraction over CloudFormation.

In short, instead of feeling like building cloud infrastructure is a never-ending game of Jenga, where one misplaced block brings the whole thing crashing down, you can just define your infrastructure using familiar code, like a wizard casting a spell. Neat!

Keeping with the Jenga metaphor, using services like AWS Cloud9, you can have multiple people looking at your AWS CDK code when you’re building out large and complex environments. 

You can use constructs to build out your resources

To paraphrase Shrek, like an onion, AWS CDK has layers. You can create constructs from level one to level three to help define your infrastructure.

Level one constructs are the lowest level constructs, and are pretty much CloudFormation allowing you to build things like you would in CloudFormation. These constructs provide a direct mapping to the AWS CloudFormation resources they represent.

Level two constructs are a higher level of abstraction. Rather than relying on the raw CloudFormation resources of level one, level two constructs make it easier to define AWS resources by providing default values and sensible assumptions.

Level three constructs are the highest-level constructs, and provide even more user-friendly APIs for defining AWS resources, using patterned style of code. This construct often bundles together multiple level two constructs into a single, higher-level construct that represents a more complex resource, like a complete AWS application or service.

So, other than constructs, how does AWS CDK work?

CDK uses file structures to keep your code inline and doing what you want it to do. The `bin` folder is where you write the code for your application, while the `lib` folder contains the references for your build. You can also use the `src` folder to add additional information about your resources, such as configuration files for software installation or setting up monitoring.

As mentioned above, with AWS CDK, you can define your infrastructure using code. For example, you can use code to specify that you want to install Apache on a certain instance or set up monitoring for a particular resource. And just like that, life is a whole lot easier.

What’s the difference between AWS CDK and CloudFormation?

The main difference between AWS CDK and CloudFormation is when building resources CDK allows for almost all modern programming languages, while CloudFormation only allows for YAML and JSON. This means CDK is more flexible when building resources. CDK also uses Cloud9 which allows multiple people to work on the code at once, unlike CloudFormation.

What’s the difference between AWS CDK and SDK?

AWS CDK is an infrastructure-as-code tool that allows developers to define AWS resources in code. On the other hand, AWS SDK, or Software Development Kit, provides a set of tools for developers to interact with AWS services, such as creating API calls and Lambda functions. While the SDK can manipulate resources, it can’t create them. 

An example of this is with SDK, you could create information to be uploaded into an S3 bucket. However, you couldn’t use SDK to create the S3 bucket.

What are the downsides of using AWS CDK?

One downside of using AWS CDK is that it requires another service, such as Cloud9, for IDE access. This means you may not have everything you need in one place, which can be inconvenient. Additionally, when multiple people are working on the same code, it can lead to problems with overlapping changes.

While AWS CDK supports most modern programming languages, it may not support all of them. You still need to have some knowledge of your chosen language to use CDK effectively.

Finally, there can be a bit of a learning curve with getting your head around CDKs level two and level three constructs. However, once you do overcome that curve, it can greatly simplify the process of building and deploying infrastructure on AWS. 

Conclusion: CDK makes building resources easier

Using AWS CDK should be seen as a fresh and new approach to launching resources, and while it's not always the answer, it can become an easy and stable way to build things in your environment. 

If you want to learn more about how to deploy compute services with this service, check out my course, “How to Deploy Compute Services with AWS CDK.”

Beth Hord

Beth Hord has been working in the IT field for a decade and has been a cloud engineer in a fast-paced environment for the last three years. She has five AWS Certifications and her RHCSA. In her personal life, she’s a heck of a baker, avid metal head, and passionate dog owner.