In let's say three major points. The first one is that CloudFormation is messy. If you're gonna write lots of resources because of its super explicit way of approach even CloudFormation is going to be a super huge YAML or JSON. Depends on your benefit but it's gonna if you have much resources, it's going to be a heavy file and not so likeable to work with.
Also, if you're gonna create relations in your CloudFormation it's going to be a hell because it's making it super messy super buggy and not even understandable for anyone that doesn't know it. CDK solves all of these notes because CDK uses classes and variables such as any other coding language to create the resources with it.
Also another major point is the multi-regional way of working with CloudFormation. As you already know, CloudFormation does not support multi-regional and if you want to deploy your CloudFormation stack in some, in multiple regions, you'll need to use stack set, a kind of patch that AWS wrote to deploy one CloudFormation stack in multiple regions. With CDK it's basically solved because CDK supports the stack out of the code. You can create as much stacks as you can inside your code and just deploy them one by one into each region you wish.
Also, CDK is basically now the native experience of AWS, which means that it's not only 100% AWS-orient, it's the only way to, the only way, the only thing you can write with CDK is basically AWS, so it's not fit to any other providers, it's full AWS service so it means it works best with AWS and only AWS. Even more than this, as I already said, CDK supports multiple languages. The most typical one is TypeScript but you can write also JavaScript and much more languages with it, which is amazing because basically, if you think about it, you can write one repo, put in this repo your already existing coding or programming functions. On the other hand, you can put in the same repo your infrastructure as code, such as in CDK, and then if you, let's say, deploy an instance with some code, you can define the instance itself in the same repo, which is basically a branding amazing way to work with infrastructure as code.
So, how does CDK work? CDK turns code into cloud formation stacks, which basically means that AWS wrote CDK on top of the old cloud formation mechanism. You're going to write it in each language you wish, as we already described, and you're going to write constructs, which means creating an S3 bucket resource or a instance resource, for example. After writing this in these resources, you're going to use the command CDK synth, which is basically a dry run of what you already wrote, and it will generate automatically the cloud formation template that describes exactly the resources you wrote in any other coding language you used. So, creating the CDK synth created a template, and then following that, you're going to use CDK deploy to deploy the stacks by actually creating cloud formation stacks with this template inside, and creating out of the stacks the resources on your AWS specified region or regions, for example.
Deploying will create two artifacts, one, an S3 bucket files that run the state, let's say, of your CDK code. It saves the resources that were created, the changes that it made, and you can track over there and see the state of the lately deployed stack. Beside, it's going to create the CloudFormation stack itself, which creates the resources out of it. Into your cloud.
So who should use CDK and when? It's a pretty typical question because the who is basically everyone, everyone that uses AWS because CDK is the 100% oriental way to approach, let's say, to create infrastructure as code over Amazon. And especially CloudFormation users that wish to migrate the CloudFormation old stacks into CDK. It's gonna be a pretty easy process to go through and we'll do it in the example following that. Another group is like any DevOps or SRE teams that are working with AWS. And besides, if you can think about it, even your developers can use CDK because now it's not a knowledge you need to experience with YAMLs or config. It's just coding, the same as any other programmatic coding you do. And besides, all of the infrastructure code users who work over AWS, it's best to work with CDK.
When? When is, I think, every time because if you're already using any infrastructure as code, it's always a good way and always a good time to start working with a tool that is officially working with AWS.
Comments