Awesome AWS CDK - Part 1 - A series on common and practical deployments with the AWS CDK
Tags: aws, awscdk, devops, iac
Published: 2021-03-14 09:24:34


# PART 1

## Introduction

This is going to be the first in a series of articles about using the AWS CDK (Cloud Development Kit) for common and practical deployment of cloud resources on AWS. This is to help those who are already familiar with AWS to deploy cloud resources using this awesome IaC (Infrastructure as Code) library from AWS.

As you may have figured, the AWS CDK is targeted at the deployment of AWS cloud infrastructure only. So if you are afraid of AWS vendor lock-in for your cloud deployments, then maybe this will not be the series for you. There are other tools that can do multi-vendor cloud deployments and provisioning (like [Terraform](https://www.terraform.io/), [Pulumi](https://www.pulumi.com/), [Serverless](https://www.serverless.com/)). 

However, if you feel like you use AWS a lot like many DevOps/Solutions Architects/Developers do then this is the series to show you practical examples of using the AWS CDK to deploy resources.

## Background
### In the beginning...
You can manually create resources on AWS using the console, command line interface or other IaC tools. And this is what people did when AWS was new. But it became evident pretty fast that this mode of provisioning cloud infrastructure was error prone and not sustainable, especially for massive and complex stacks of resources. These frustrations led to the birth of [Cloudformation](https://aws.amazon.com/cloudformation/) in 2011.

### Cloudformation 
AWS Cloudformation is AWS' managed service for provisioning cloud infrastructure and services. You do this using a JSON or YAML template file that defines what resources you would like AWS to Create, Update or Destroy. Cloudformation consumes file and makes the necessary changes to your deployed stack of resources.

Cloudformation is the backbone service of automatically deployed resources on AWS. It ensures consistency of your deployed resources and can keep track of drifts (when resources are created, updated or destroyed outside of the Cloudformation template file).

The problem is Cloudformation template files are ridiculously hard to write, read, update and manage. After all they are basic YAML/JSON. Its fine if you are provisioning a few resources. But it is completely unmanageable with human effort once you exceed 20 resources. 

This is where the CDK comes in.

### Cloud Development Kit
The AWS CDK is a library of functions that will generate a Cloudformation template and use it to provision resources in AWS. It allows you to write code to define in your favorite language to create these Cloudformation templates.

With the CDK, the ability to have access to intellisense from your code editor, ability to break up resources into logical parts, type checking, enums etc means that the tendency to make errors when configuring resources dramatically reduces. You can also write tests for the infrastructure you want to deploy to ensure that whatever changes made in the IaC are not going to break your deployed stack of resources or cost you millions when you mistakenly provision beyond your means. 

Its been a joy working with CDK for the past year for me and it is hard to go back to other solutions like Terraform, Serverless, SAM for AWS resource provisioning.  

### It's not all roses yet though
No project is perfect. The AWS CDK, as great as it is, is also a recent project (launched in July 2019) so it doesn't yet cover everything possible to deploy on AWS (Even Cloudformation doesn't cover everything possible in AWS yet). Some things will need manual configuration via the console or command line interface. There are also minor bugs, fast changing interfaces, deprecations etc as the CDK development tries to catch up to and keep up with the pace at which AWS releases new services and updates. Maybe within a year many of my own code examples from this series will have some deprecations. But the core API and concepts will remain the same. Also, for most common services, the CDK will have you covered. 

## Conclusion
Note:
- I will focus on simple and common deployments. 
- I will use github actions as my CI/CD tool.

There are other projects out there that focus on patterns like the awesome [cdk patterns project](https://cdkpatterns.com/) which concentrates on serverless deployments with the cdk and AWS' own [aws-cdk-examples project](https://github.com/aws-samples/aws-cdk-examples) which has tons of great examples on using the cdk. I drew tons of inspiration and learning from these projects.

My series will focus on simple common deployments with a heavy leaning on practicality. This means I will take you through some best practices as well as well as my own experience.

I will use Typescript because:
- The CDK API is essentially the same in Typescript, Python, .Net, Java. The language itself isn't too important. 
- The CDK is also written in Typescript and then wrapped for use in other languages.
- It's awesome!

Hope you can stick with me throughout. See you in part 2!


-------
Hi I'm [Emmanuel](https://emmanuelnk.com)! I write about Software and DevOps.

If you liked this article and want to see more, add me on [LinkedIn](https://www.linkedin.com/in/emmanuel-nsubuga-kyeyune/) or follow me on [Twitter](https://twitter.com/emmanuel_n_k)