Introduction to the AWS Cloud Development Kit (AWS CDK) - krdheeraj51/aws-labs GitHub Wiki
The AWS Cloud Development Kit (AWS CDK) is an open-source software development kit used for defining cloud infrastructure as code. It allows you to define your infrastructure using familiar modern programming languages like TypeScript, JavaScript, Python, Java, and C#/.Net, and then deploy it through AWS CloudFormation.
Before diving deeper into the AWS CDK, it's essential to understand its core terminology. Let's familiarize ourselves with fundamental terms like apps, stacks, constructs, and resources, which form the basis of the AWS CDK's architecture.
Key Concepts
App
- An App represents the project's deliverable scope.
- It's a container for one or more Stacks.
- Stacks within a single App can easily reference each other's resources.
Stack
- The unit of deployment in the CDK is the Stack.
- All AWS resources defined within a Stack are provisioned as a single unit.
- Similar to a CloudFormation Stack, CDK allows organizing resources into distinct stacks, such as:
- IAM Stack/Security Stack
- Networking Stack
- Function Stack
- DB Stack
Construct
- Constructs are the fundamental building blocks of AWS applications.
- The CDK provides a collection of constructs called the Constructs Library, which includes constructs for every AWS service.
- A Construct can represent either a single AWS resource (like an S3 bucket) or multiple related AWS resources.
- It acts as a "cloud component" and encapsulates all the information CloudFormation needs to create that component.
Resource
- You create an instance of a Resource using its corresponding Construct.
- This typically involves:
- Passing the scope as the first argument.
- Providing the logical ID of the construct as the second argument.
- Setting the configuration properties (props) as the third argument.
CDK Four Step Process
The CDK uses a four-step process to convert into a CloudFormation template: construct, prepare, validate, and synthesize. Since aspects are used during the second step, you need to understand how the first two steps are related.
Relationships
The following diagram illustrates the relationships between AWS CDK apps, stacks, constructs, and resources: