AWS Cloud Development Kit (AWS CDK) – an open-source software development framework for defining cloud infrastructure in code and provisioning it through AWS CloudFormation
Consists of two(2) parts:
CDK Construct Library
A collection of pre-written modular and reusable pieces of code, called constructs, that you can use, modify, and integrate to develop your infrastructure quickly.
CDK CLI
A command-line tool for interacting with CDK apps
Supports the following programming languages:
TypeScript,
JavaScript
Python
Java
C#/.Net
Go
Difference between Cfn and CDK
Cfn defines infrastructure declaratively
CDK defines infrastructure imperatively
Core Concepts
Projects:
Represents the files and folders that contain your CDK code.
Vary based on your programming language.
Universal Files and Folders:
.git
.gitignore
README.md
cdk.json – Configuration file for the AWS CDK. This file provides instructions to the AWS CDK CLI regarding how to run your app.
Apps:
A collection of one or more CDK stacks.
You create an app by defining an app instance in the application file of your project.
Stack ‘constructs’ are defined within the scope of an App construct.
Stacks within a single app can easily refer to each other’s resources and properties.
The overall grouping of your stacks and constructs is known as your CDK App
Stacks:
The smallest single unit of deployment
It represents a collection of AWS resources that you define using CDK constructs.
When you deploy CDK apps, the resources within a CDK stack are deployed together as an AWS CloudFormation stack.
You define a stack by extending or inheriting from the Stack construct.
Stack constructs are defined within the scope of an App construct
Stacks are deployed as an AWS CloudFormation stack
When you run the 'cdk synth' command for an app with multiple stacks, the cloud assembly includes a separate template for each stack instance.
Stages:
Represents a group of one or more CDK stacks that are configured to deploy together.
Use stages to deploy the same grouping of stacks to multiple environments, such as development, testing, and production.
Constructs:
The basic building blocks of AWS Cloud Development Kit (AWS CDK) applications.
A construct is a component within your application that represents one or more AWS CloudFormation resources and their configuration.
Constructs are classes that you import into your CDK applications from the AWS Construct Library
Construct Levels:
Level 1 (L1):
Also known as CFN resources.
The lowest-level construct offers no abstraction.
Each L1 construct maps directly to a single AWS CloudFormation resource.
Level 2 (L2):
Also known as curated constructs.
Developed by the CDK team and are usually the most widely used construct type.
Maps directly to single AWS CloudFormation resources but with higher abstraction.
Level 3 (L3):
Also known as patterns.
The highest level of abstraction.
Contains a collection of resources that are configured to work together to accomplish a specific task or service within your application.
Used to create entire AWS architectures for particular use cases in your application.
Context Values:
Key-value pairs that can be associated with an app, stack, or construct.
Supplied to your app either from a file (usually either cdk.json or cdk.context.json in your project directory) or on the command line.
Visible to child constructs, but not to parents or siblings