Cloud Development Kit (CDK)
Last updated
Last updated
Define your cloud infrastructure using familiar language.
Supported languages includes Java
, Python
, Typescript/Typescript
, .NET
.
Contains high level components called constructs
.
The code is then compiled into a CloudFormation Template(CFT) (json/yaml). So this is step above CFT
.
You can therefore deploy infrastructure and application runtime code together.
It is great for Lambda functions
Great for docker container ECS
/EKS
CDK and SAM can be used to test your CDK
apps locally.
For this first run cdk synth
command. This will generate a CFT
.
Secondly run sam local invoke -t <template file> <function-name>
to call the function.
CDK construct
is a component that encapsulates everything CDK needs to create the final CloudFormation stack.
Can represent a single or group of AWS resources.
Construct Hub
is a community that contains AWS, third-party and open source CDKs.
Constructs are generated based on CloudFormation Resource Specification.
The name of construct starts with Cfn
.
Level 1
CFN Resources
Represents all resources directly available in Cloud Formation
Level 2
Intent Based
Similar to Level 1, but with sensible defaults and boilerplates, provides method
Level 3
Pattern based
Represent multiple related resources, helps to complete most common tasks
To test CDK apps, use CDK Assertions module, combined with popular test frameworks like Jest
or Pytest
.
Two types of tests
Fine-grained Assertions
Snapshot Tests
Install the CDK, requires nodejs
.
Initialize the CDK
application
Returns CDK app stack
Add your code to the CDKAppStack
created in step 3 to the file cdk-app-stack.js
.
Make the required setup based on your infrastructure added in step 4.
Run the command cdk bootstrap
once per account per region. This will use cdk.json
file present in the root of directory to create the necessary CDKToolKit
and necessary resources like AWS S3 and IAM roles before it can deploy into an AWS environment.
AWS Environment = account and region
Run the command cdk synth
optionally to generate the CFT
.
Run the command cdk deploy
to deploy the application.
Run the command cdk destroy
to destroy the stack created in deployment.
cdk diff
will give you difference between Local CDK and deployed stack.