CDK commands

stateDiagram-v2 [*] --> new_directory new_directory --> CDK_skeleton: cdk init app CDK_skeleton --> CDK_App: edit code CDK_App --> Template_generated: cdk synth Template_generated --> CDK_App : edit code CDK_App --> Stack_Deployed: cdk deploy Stack_Deployed --> Stack_destroyed Stack_Deployed --> CDK_App: edit code Stack_destroyed --> [*]

To understand how CDK works, you have to understand the concepts of a CloudFormation Template, a CloudFormation Stack and an AWS Infrastructure Resource.

The code in this example is in the file hellocdk.go.

The CloudFormation Template

The template is a yaml or json file which describes an AWS Infrastructure Resource.

The AWS CloudFormation service provides API calls for interpreting several resources, which are bundled together in the template and create them together.

All the created resources from one template is called a Stack.

sequenceDiagram participant A as AWS cli participant T as Template participant C as Stack participant RES as AWS Resources A ->> T : read A ->> C : send API Call with template C ->> RES : create Ressource

Examples for AWS resources are the SNS topic, an EC2 instance and a few hundreds more…

CDK generates Templates and Stacks

The cdk called with cdk deploy generates a Template from the program and then sends it to the cloudformation service, which creates the stack.

The cdk destroy call deletes the stack.

Now let’s see a walkthrough in the next chapter

See also