As a result of working on hundreds of projects, nClouds’ engineers have extensive experience with AWS CloudFormation (CloudFormation) and building infrastructure as code (IaC). Though CloudFormation is efficient, reliable, and effective, it is not easy to test or debug, nor is it easily scalable or reusable. In a short time, AWS Cloud Development Kit (AWS CDK) has become an invaluable tool for our developer-centric DevOps teams. We believe that AWS CDK is the beginning of a new future for IaC. Check out our nSights TechTalk on CDK here.
In this blog, I’ll describe what the AWS CDK is and explain why your DevOps teams should consider using it.
What is AWS CDK?
AWS CDK is an open-source software development framework for defining cloud infrastructure as code (IaC) AWS introduced in July 2019. Because AWS CDK uses CloudFormation as a foundation, it has all the advantages of CloudFormation while enabling nClouds’ engineers to provision IaC using modern programming languages like Typescript, C# (C-Sharp), Java, and Python. In a sense, this is AWS’s answer to HashiCorp Terraform. Note: AWS CDK is intended for moderate to highly-experienced AWS users.
AWS CDK is a tool that can be used in any AWS IaC project, even the simple ones. It can be particularly useful when you want to:
- Involve your developers more with IaC (embracing a DevOps culture) so that they can leverage their expertise on the programming languages they already know.
- Reuse code and create libraries and modules.
Here’s how it works
Source: AWS Cloud Development Kit. (n.d.). https://aws.amazon.com/cdk/
There are two ways to deploy infrastructure using AWS CDK. You can either deploy the infrastructure directly by using the AWS CDK Toolkit (the CLI command cdk) or synthesize the project into CloudFormation templates and deploy the infrastructure the traditional way. The advantage of using the cdk command is that you can diff against a deployed stack line by line to see the impact of a code change before you push it.
Two core concepts of AWS CDK are stacks and constructs.
Stacks are basic units of deployment in AWS CDK that are composable. You can use one or multiple stacks in a project. A stack can share values by consuming resources from another stack. Behind the scenes, AWS CDK uses the CloudFormation import value to pass around different CloudFormation stacks.
Like CloudFormation stacks, AWS CDK stacks contain constructs, each of which defines one or more AWS resources. Constructs contain everything CloudFormation needs to create a reusable cloud component.
There are low-level constructs (called L1) with a Cfn prefix that map to one of CloudFormation’s resources and properties. You can work with them just like you do with CloudFormation (instead of JSON or YAML) by defining them in your programming language.
Higher-level constructs are called L2. By entering a single line of code, you can build an Amazon Virtual Private Cloud (Amazon VPC) network address translation (NAT) gateway in each Availability Zone (AZ) or different types of networks, for example.
Benefits of AWS CDK
- Enables easier cloud onboarding. Use existing skills and tools and preconfigured cloud resources with proven defaults to build cloud infrastructure.
- Accelerates the development process. Define the infrastructure using familiar programming languages. Testing frameworks enable unit testing within the full programming language. It can be used with your integrated development environment (IDE).
- Is customizable and reusable. Customizable code is modular and reusable to imbue new projects with security, compliance, and governance best practices.
- Leverages the full power of the programming language, such as conditional loops, string interpolation, etc. So, if a team uses Python, they can put their infrastructure definition in the same kind of code.
- Performs type checking for the infrastructure to avoid compiler errors.
For a step-by-step tutorial on creating and deploying a simple AWS CDK app, take a look at the AWS Developer Guide for AWS CDK.
- With higher-level constructs, developers may lose some control over what they’re creating. However, the trade-off may be worth it because AWS CDK provides a friendly and easy-to-use module.
- While, as mentioned earlier, you can define the infrastructure using familiar programming languages, it’s important to have standardization. Without standardization, the programming language used for the code can become complex very easily, making it more challenging to maintain. Because AWS CDK uses CloudFormation under the hood, keep in mind that it’s tied to some of CloudFormation’s caveats and limitations.
It is worth noting that nClouds’ engineers have been developing nCodeLibrary, an AWS CDK-compatible IaC repository. nCodeLibrary is now an extensive IaC opportunity that enables our clients to spin up cloud environments quickly with complete confidence. It provides predesigned configurations that simplify the provisioning of resources on AWS.
All nCodeLibrary resources have been previously tested and optimized by nClouds’ premiere engineering team. It provides IaC modules that create a secure and high-performing version of a cloud resource. By building complete environments with nCodeLibrary modules, the overall infrastructure automatically inherits AWS Well-Architected best practices guidelines.
Infrastructure resources that have been created using nCodeLibrary are embedded with nClouds’ naming and tagging standards for resources. This standardization simplifies tasks by environment. Resources immediately integrate with nClouds 24/7 Support Services, with automated monitoring and alerts on designated metrics for all deployed environments.
AWS CDK is a code-first approach to defining cloud application infrastructure. Since that launch, and following the “release early, release often” philosophy, more than 30 versions of AWS CDK have been released to deliver new features as quickly as possible. As AWS CDK continues to gain more traction, new features will be developed quickly and released often.
Check out nCodeLibrary, an AWS CDK-compatible IaC repository, to simplify the provisioning of resources on AWS and build an infrastructure that automatically inherits AWS Well-Architected best practices guidelines.
See more information about AWS CDK Consulting Services.
Need help with DevOps and infrastructure modernization on AWS? The nClouds team is here to help with that and all your AWS infrastructure requirements.