CDK All the Way
What is AWS CDK?
AWS CDK (Cloud Development Kit) is an open-source software development framework for defining cloud infrastructure in code using familiar programming languages such as TypeScript, Python, Java, and C#. With CDK, you can define your AWS infrastructure using object-oriented programming concepts and reusable code modules. CDK generates CloudFormation templates from the code, so you get the benefits of both declarative and imperative programming models. The end result is that you can create, manage, and deploy your AWS infrastructure using code that is easy to read, maintain, and reuse.
Why we use CDK?
Managing your cloud infrastructure by hand is a hassle. IAC, aka Infrastructure as Code approach enables you to manage and provision your infrastructure in a declarative, automated and repeatable way using code. This approach brings many benefits, including version control, reproducibility, and the ability to automate deployments and testing.
Even though there are options like the Serverless Framework, pure CloudFormation, or even Terraform in AWS projects our clear preference is CDK. CDK allows you to utilize fully fledged programming languages (yes, multiple language choices) instead of just configuration to define your infrastructure allowing you to make easily reusable components instead of a lot of copy/pasting. It also contains a lot of useful resource methods and other tools to cut down time spent defining your infrastructure code.
Actually, we’ve come to the conclusion that even in small projects, it’s better to use CDK than to manage them by hand or use some other means. Consistency brings quality and what usually happens is that small projects become larger projects requiring more scalability and a structured approach for managing the infrastructure.
Concrete advantages of using CDK?
Beyond providing a consistent and repeatable way of managing your infrastructure, CDK provides a bunch of productivity enhancing features that make your life easier.
For example, when managing the access rights (IAM), CDK offers the following advantages:
Re-usable policy modules.
Lots of helpful resource methods for managing policies.
Automatic behind the scenes role and policy generation in places where it makes sense.
How to start with CDK?
AWS provides a nice guide that will help you get started: https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html