Cloud Development Kit (CDK)
Icon
About
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
CDK and SAM can be used to test your
CDKapps locally.For this first run
cdk synthcommand. This will generate aCFT.Secondly run
sam local invoke -t <template file> <function-name>to call the function.
CDK construct
CDK constructis a component that encapsulates everything CDK needs to create the final CloudFormation stack.Can represent a single or group of AWS resources.
Construct Hubis 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.
Levels of CDK
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
CDK Testing
To test CDK apps, use CDK Assertions module, combined with popular test frameworks like
JestorPytest.Two types of tests
Fine-grained AssertionsSnapshot Tests
Working with CDK CLI
Install the CDK, requires
nodejs.sudo npm install -g aws-sdk-libInitialize the
CDKapplicationcdk init app --language <language> ## Example cdk init app --language javascriptReturns CDK app stack
cdk lsAdd your code to the
CDKAppStackcreated in step 3 to the filecdk-app-stack.js.Make the required setup based on your infrastructure added in step 4.
Run the command
cdk bootstraponce per account per region. This will usecdk.jsonfile present in the root of directory to create the necessaryCDKToolKitand 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 synthoptionally to generate theCFT.Run the command
cdk deployto deploy the application.Run the command
cdk destroyto destroy the stack created in deployment.cdk diffwill give you difference between Local CDK and deployed stack.
Last updated