Under the hood, AWS CDK is more of a transpiler. Transpilers are programs that convert a piece of source code from one high- level language into another. The output from these programs has the same level of abstraction as the input. This is fundamentally different from compilers as they produce low-level code that directly interacts with the underlying machine, and is more performant.
Pulumi, on the other hand, offers deeper integrations with the programming runtime and the cloud provider by not depending on an intermediate state, such as AWS CloudFormation templates in the case of AWS CDK. Pulumi takes control of managing the life cycle of the resources that the user defined a target state for. This level of integration provides additional benefits with efficient unit and integration testing capabilities by leveraging mocked responses and other constructs.
Figure 6.1 shows a visual mapping of the different infrastructure management approaches and the corresponding tools and frameworks:
Figure 6.1 – Different approaches to managing infrastructure in AWS and the corresponding tools
Having discussed all the different tools and frameworks for managing your AWS infrastructure, let’s dive deeper into some CDK specifics, which is our focus for this chapter.
What is AWS CDK?
AWS CDK enables users to leverage general-purpose programming constructs such as classes, objects, and inheritance to generate AWS CloudFormation templates, and also deploy them in the respective AWS account and region. It does not manage the deployment orchestration itself but rather offloads this responsibility to AWS CloudFormation. This means that it is also, in a way, dependent on the capabilities of AWS CloudFormation and the interfaces exposed by the service.
With familiar programming languages and integrations with commonly used IDEs, it’s quite easy to start building infrastructure by leveraging the reusable classes offered by the development kit. The high-level constructs automatically use sensible defaults, which not only improves the overall security posture of your infrastructure but also empowers the users to do more with less code. When working with AWS-managed services at the application level, typically, teams combine the definition of infrastructure resources with application components, thereby deploying the whole system as a single cloud deployment. Additionally, this allows configuration reuse and efficient dependency management of both layers.
Using programming idioms such as loops, parameters, and conditionals, you can substantially reduce the overall configuration effort. Also, since the users are now working with programming languages they are already used to, it becomes easy to enforce DevOps best practices around code reviews, tests, and seamless infrastructure deployments across multiple stages of the software delivery pipeline.
CDK offers command-line tools to bootstrap project repositories and create IaC templates to manage stacks. The kit itself is developed in Typescript and the JSII framework (also developed by AWS), which enables the portability of the underlying implementation to other programming languages.
Let’s discuss some key concepts that you will come across when working with CDK.