1 00:00:00,180 --> 00:00:02,520 ‫Okay, so what are the important commands 2 00:00:02,520 --> 00:00:04,650 ‫to know for the CDK? 3 00:00:04,650 --> 00:00:07,260 ‫So you have all of these and I will walk you through them 4 00:00:07,260 --> 00:00:09,630 ‫and this should make sense to you right away. 5 00:00:09,630 --> 00:00:13,290 ‫So the first one is to install the CDK CLI and libraries 6 00:00:13,290 --> 00:00:16,110 ‫so you can start writing your CDK stack. 7 00:00:16,110 --> 00:00:19,830 ‫The second one, cdk init initializes an app 8 00:00:19,830 --> 00:00:21,927 ‫from a specified template. 9 00:00:21,927 --> 00:00:25,260 ‫And so you can choose Python, JavaScript and so on. 10 00:00:25,260 --> 00:00:27,630 ‫Cdk synth synthesizes 11 00:00:27,630 --> 00:00:29,280 ‫and prints the CloudFormation template. 12 00:00:29,280 --> 00:00:33,180 ‫So this is the transformation between your CDK stack as code 13 00:00:33,180 --> 00:00:36,150 ‫into a CloudFormation templates. 14 00:00:36,150 --> 00:00:39,810 ‫Cdk bootstrap is something we'll see in the next slide, 15 00:00:39,810 --> 00:00:42,030 ‫so I will just skip it for now. 16 00:00:42,030 --> 00:00:44,700 ‫Cdk deploy is to deploy the stack. 17 00:00:44,700 --> 00:00:46,350 ‫So once you have a CloudFormation template, 18 00:00:46,350 --> 00:00:48,240 ‫of course, you want to deploy it. 19 00:00:48,240 --> 00:00:53,040 ‫Cdk diff is to look at the difference of the local CDK. 20 00:00:53,040 --> 00:00:55,410 ‫So whatever you have changed 21 00:00:55,410 --> 00:00:58,350 ‫and what is actually deployed on CloudFormation. 22 00:00:58,350 --> 00:01:01,500 ‫And cdk destroy is to destroy the stacks. 23 00:01:01,500 --> 00:01:03,960 ‫So the last little thing that we haven't discussed 24 00:01:03,960 --> 00:01:06,930 ‫in depth is cdk bootstrap. 25 00:01:06,930 --> 00:01:08,910 ‫So what is bootstrapping in CDK? 26 00:01:08,910 --> 00:01:10,980 ‫Well, bootstrapping is the process 27 00:01:10,980 --> 00:01:13,590 ‫of provisioning resources for CDK 28 00:01:13,590 --> 00:01:17,940 ‫before you can deploy CDK apps into an AWS environment. 29 00:01:17,940 --> 00:01:19,950 ‫So what is an environment in AWS? 30 00:01:19,950 --> 00:01:21,180 ‫Well, for CDK, 31 00:01:21,180 --> 00:01:24,030 ‫it's the combination of an account and a region. 32 00:01:24,030 --> 00:01:26,130 ‫So the idea is that before you are able 33 00:01:26,130 --> 00:01:28,860 ‫to deploy to an account and a region, 34 00:01:28,860 --> 00:01:33,860 ‫you must deploy a CloudFormation stack called the CDKToolkit 35 00:01:33,870 --> 00:01:35,700 ‫that will contain an S3 bucket 36 00:01:35,700 --> 00:01:37,530 ‫and it will contain an IAM role. 37 00:01:37,530 --> 00:01:39,945 ‫And these are necessary prerequisites 38 00:01:39,945 --> 00:01:44,820 ‫to deploying any CDK stack in that specified environment. 39 00:01:44,820 --> 00:01:46,770 ‫So when you are deploying 40 00:01:46,770 --> 00:01:49,500 ‫to a new account and region combination, 41 00:01:49,500 --> 00:01:52,410 ‫so a new environment, you do cdk bootstrap 42 00:01:52,410 --> 00:01:57,097 ‫and then aws://aws_account/aws_region. 43 00:01:58,920 --> 00:02:00,390 ‫So here is what happens. 44 00:02:00,390 --> 00:02:02,430 ‫We have the account and the region, 45 00:02:02,430 --> 00:02:04,440 ‫and the user runs the bootstrap. 46 00:02:04,440 --> 00:02:06,810 ‫A CloudFormation stack called CDKToolkit 47 00:02:06,810 --> 00:02:09,131 ‫is going to be created with what we need. 48 00:02:09,131 --> 00:02:14,131 ‫Now, if you try to deploy a CDK stack after this, 49 00:02:14,370 --> 00:02:15,900 ‫everything is going to work 50 00:02:15,900 --> 00:02:19,950 ‫but if you didn't bootstrap into your environment, 51 00:02:19,950 --> 00:02:23,940 ‫you will have an error when trying to deploy your CDK stack, 52 00:02:23,940 --> 00:02:27,150 ‫which will say policy contains a statement 53 00:02:27,150 --> 00:02:29,820 ‫with one or more invalid principle. 54 00:02:29,820 --> 00:02:31,680 ‫That's because you're missing the IAM role. 55 00:02:31,680 --> 00:02:32,880 ‫So that should make sense. 56 00:02:32,880 --> 00:02:35,220 ‫Hopefully now you understand what bootstrapping is 57 00:02:35,220 --> 00:02:38,700 ‫and all the necessary commands to make CDK work. 58 00:02:38,700 --> 00:02:41,913 ‫I hope you liked it and I will see you in the next lecture.