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.
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:
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.
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.
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.