1 00:00:00,120 --> 00:00:02,220 ‫So Constructs in CDK are very important, 2 00:00:02,220 --> 00:00:03,630 ‫and we've seen them before. 3 00:00:03,630 --> 00:00:06,450 ‫They are components that encapsulates everything 4 00:00:06,450 --> 00:00:10,110 ‫CDK needs to create the final CloudFormation stack. 5 00:00:10,110 --> 00:00:13,140 ‫And so a Construct can be a single AWS resource, 6 00:00:13,140 --> 00:00:14,820 ‫such as an S3 bucket, 7 00:00:14,820 --> 00:00:18,810 ‫or it can be a combination of multiple related resources, 8 00:00:18,810 --> 00:00:22,650 ‫for example, an SQS worker queue with some computes. 9 00:00:22,650 --> 00:00:24,420 ‫So how do we get these Constructs? 10 00:00:24,420 --> 00:00:26,280 ‫Well, there is a Construct Library, 11 00:00:26,280 --> 00:00:28,050 ‫which is a collection of Constructs 12 00:00:28,050 --> 00:00:29,760 ‫that is included in the CDK 13 00:00:29,760 --> 00:00:33,270 ‫and that contains the Constructs for every AWS resource. 14 00:00:33,270 --> 00:00:35,160 ‫And you have three levels of Constructs: 15 00:00:35,160 --> 00:00:37,080 ‫Level 1, Level 2, and Level 3. 16 00:00:37,080 --> 00:00:39,000 ‫We'll see them in the next slides. 17 00:00:39,000 --> 00:00:40,560 ‫Also, you have the Construct Hub. 18 00:00:40,560 --> 00:00:42,540 ‫This is when you have Constructs from AWS 19 00:00:42,540 --> 00:00:46,200 ‫but also third parties and open-source CDK community 20 00:00:46,200 --> 00:00:51,200 ‫to allow you to create your CDK stacks faster and better. 21 00:00:51,690 --> 00:00:53,880 ‫So let's talk about the Layer 1 Constructs. 22 00:00:53,880 --> 00:00:55,830 ‫They're called CFN Resources 23 00:00:55,830 --> 00:00:57,900 ‫because they represent all the resources 24 00:00:57,900 --> 00:01:00,240 ‫available within CloudFormation. 25 00:01:00,240 --> 00:01:03,120 ‫So here, in this example, we do a bucket. 26 00:01:03,120 --> 00:01:06,090 ‫And it's new s3.CfnBucket. 27 00:01:06,090 --> 00:01:10,320 ‫And so we define the exact same properties 28 00:01:10,320 --> 00:01:14,640 ‫as the one from the CloudFormation Resource Specifications. 29 00:01:14,640 --> 00:01:16,020 ‫And you know this is Layer 1 30 00:01:16,020 --> 00:01:18,120 ‫because it starts with Cfn. 31 00:01:18,120 --> 00:01:21,690 ‫So a CFN bucket must have all the resource properties 32 00:01:21,690 --> 00:01:23,610 ‫that are required for a bucket. 33 00:01:23,610 --> 00:01:24,960 ‫So, bucket name. 34 00:01:24,960 --> 00:01:27,630 ‫And you can configure all of them individually. 35 00:01:27,630 --> 00:01:30,060 ‫So if you wanted to just migrate 36 00:01:30,060 --> 00:01:32,790 ‫from CloudFormation to CDK, 37 00:01:32,790 --> 00:01:35,910 ‫one by one, all your resources into code, 38 00:01:35,910 --> 00:01:40,410 ‫you could use CFN bucket, CFN SQS queue, and so on. 39 00:01:40,410 --> 00:01:42,090 ‫And that would be enough. 40 00:01:42,090 --> 00:01:45,060 ‫But that would be using Layer 1 of CDK 41 00:01:45,060 --> 00:01:46,980 ‫because this is quite basic. 42 00:01:46,980 --> 00:01:48,600 ‫Then you go into Layer 2. 43 00:01:48,600 --> 00:01:51,840 ‫So Layer 2 is AWS resources 44 00:01:51,840 --> 00:01:53,460 ‫but with a higher level. 45 00:01:53,460 --> 00:01:55,110 ‫Because now we talk about intent. 46 00:01:55,110 --> 00:01:57,300 ‫This is a higher level Construct. 47 00:01:57,300 --> 00:02:00,000 ‫So if we have a look at what's in bottom, 48 00:02:00,000 --> 00:02:02,160 ‫here we have an s3.Bucket. 49 00:02:02,160 --> 00:02:05,010 ‫So the difference is that it doesn't start with Cfn. 50 00:02:05,010 --> 00:02:07,830 ‫And then, as we can see, we have versioned: true. 51 00:02:07,830 --> 00:02:11,430 ‫And then encryption, s3.BucketEncryption.KMS. 52 00:02:11,430 --> 00:02:13,740 ‫And then, automatically, knows how to do this. 53 00:02:13,740 --> 00:02:15,930 ‫And then, out of this, from the bucket, 54 00:02:15,930 --> 00:02:17,400 ‫we can get, for example, 55 00:02:17,400 --> 00:02:21,660 ‫what is the HTTP URL of a specific object out of it. 56 00:02:21,660 --> 00:02:23,820 ‫So we have extra methods out of it. 57 00:02:23,820 --> 00:02:25,770 ‫So when you use a Layer 2 Construct, 58 00:02:25,770 --> 00:02:27,630 ‫you have similar functionality as Layer 1, 59 00:02:27,630 --> 00:02:30,450 ‫but now we have convenient defaults and boilerplates. 60 00:02:30,450 --> 00:02:31,650 ‫So you don't need to know 61 00:02:31,650 --> 00:02:33,870 ‫everything about the resource properties. 62 00:02:33,870 --> 00:02:35,370 ‫And then you have added methods, 63 00:02:35,370 --> 00:02:39,150 ‫such as bucket.addLifeCycleRule. 64 00:02:39,150 --> 00:02:41,910 ‫And this would allow you to just add the Lifecycle rule, 65 00:02:41,910 --> 00:02:43,230 ‫even though, behind the scenes, 66 00:02:43,230 --> 00:02:46,263 ‫it may be a bit more complicated in raw CloudFormation. 67 00:02:47,400 --> 00:02:49,440 ‫Then you have Layer 3 Constructs. 68 00:02:49,440 --> 00:02:51,060 ‫And these are called Patterns 69 00:02:51,060 --> 00:02:54,060 ‫because they represent multiple related resources. 70 00:02:54,060 --> 00:02:57,810 ‫So here what we have is a Lambda Rest API. 71 00:02:57,810 --> 00:03:00,060 ‫And then we add resources and add resources, 72 00:03:00,060 --> 00:03:02,400 ‫and do an HTTP Integration, and so on. 73 00:03:02,400 --> 00:03:05,670 ‫And so, this Layer 3 Patterns 74 00:03:05,670 --> 00:03:08,580 ‫will help you complete most common tasks in AWS, 75 00:03:08,580 --> 00:03:11,340 ‫such as, for example, creating a Rest API 76 00:03:11,340 --> 00:03:12,720 ‫with an API Gateway. 77 00:03:12,720 --> 00:03:14,550 ‫But instead of configuring 78 00:03:14,550 --> 00:03:17,730 ‫every single little resource behind the scene, 79 00:03:17,730 --> 00:03:20,220 ‫you have a much easier API to deal with, 80 00:03:20,220 --> 00:03:21,810 ‫where you just define the API, 81 00:03:21,810 --> 00:03:23,970 ‫and then you define the resources and the methods, 82 00:03:23,970 --> 00:03:26,970 ‫and the Lambda functions, but very easily. 83 00:03:26,970 --> 00:03:29,700 ‫You can also have, for example, an ECS pattern 84 00:03:29,700 --> 00:03:31,860 ‫where you have an Application Load Balancer 85 00:03:31,860 --> 00:03:33,270 ‫with a Fargate Service, 86 00:03:33,270 --> 00:03:35,160 ‫which can be extremely complicated to write 87 00:03:35,160 --> 00:03:36,870 ‫as raw CloudFormation. 88 00:03:36,870 --> 00:03:40,080 ‫But with CDK, you just fill in the blanks, 89 00:03:40,080 --> 00:03:43,260 ‫and automatically you have your ALB and your Fargate Service 90 00:03:43,260 --> 00:03:44,910 ‫connected on the correct ports 91 00:03:44,910 --> 00:03:47,220 ‫with the correct security groups, and so on. 92 00:03:47,220 --> 00:03:48,690 ‫And the correct listeners. 93 00:03:48,690 --> 00:03:50,700 ‫So, hopefully, you now understand the differences 94 00:03:50,700 --> 00:03:53,100 ‫between all the layers in CDK Constructs 95 00:03:53,100 --> 00:03:55,230 ‫and the power of CDK. 96 00:03:55,230 --> 00:03:56,520 ‫So I hope you liked it, 97 00:03:56,520 --> 00:03:58,533 ‫and I will see you in the next lecture.