1 00:00:00,120 --> 00:00:01,750 ‫Let's talk about resources. 2 00:00:01,750 --> 00:00:03,510 ‫So resources, they're your core 3 00:00:03,510 --> 00:00:06,270 ‫of your CloudFormation templates and they're mandatory. 4 00:00:06,270 --> 00:00:07,890 ‫Your CloudFormation template cannot work 5 00:00:07,890 --> 00:00:09,610 ‫without the Resources block. 6 00:00:09,610 --> 00:00:11,580 ‫And the resources, as the name indicates, 7 00:00:11,580 --> 00:00:13,870 ‫represent the different AWS components-- 8 00:00:13,870 --> 00:00:14,870 ‫that's just a synonym-- 9 00:00:14,870 --> 00:00:16,800 ‫that will be created and configured. 10 00:00:16,800 --> 00:00:18,320 ‫And the resources are declared 11 00:00:18,320 --> 00:00:19,510 ‫and they can reference each other, 12 00:00:19,510 --> 00:00:21,340 ‫so you can link the resources together. 13 00:00:21,340 --> 00:00:23,070 ‫For example, you can link a security group 14 00:00:23,070 --> 00:00:25,310 ‫and an EC2 instance. 15 00:00:25,310 --> 00:00:27,420 ‫AWS will figure out the creation, updates, 16 00:00:27,420 --> 00:00:28,970 ‫and deletion of the resources for us, 17 00:00:28,970 --> 00:00:31,540 ‫which is super nice and you should know there are 18 00:00:31,540 --> 00:00:34,600 ‫over 224 types of resources. 19 00:00:34,600 --> 00:00:36,325 ‫So I cannot teach you all of them, right? 20 00:00:36,325 --> 00:00:39,920 ‫But any resource has the following form. 21 00:00:39,920 --> 00:00:41,660 ‫They're AWS, then the product name, 22 00:00:41,660 --> 00:00:43,920 ‫and then the data type name. 23 00:00:43,920 --> 00:00:46,540 ‫So usually, you're reading this identifier variable 24 00:00:46,540 --> 00:00:48,860 ‫to figure out what we're going to create. 25 00:00:48,860 --> 00:00:51,610 ‫So how do I find all these resources documentation? 26 00:00:51,610 --> 00:00:54,690 ‫Well, there is this great link that has all of them, 27 00:00:54,690 --> 00:00:57,230 ‫so I can't teach you all the resources, 28 00:00:57,230 --> 00:01:00,000 ‫but I can teach you how to find a link that shows them 29 00:01:00,000 --> 00:01:01,990 ‫and so then you just read the doc. 30 00:01:01,990 --> 00:01:04,200 ‫For example, we're going to read the doc together 31 00:01:04,200 --> 00:01:06,560 ‫just for the EC2 instance, 32 00:01:06,560 --> 00:01:08,300 ‫just to get a feeling for it. 33 00:01:08,300 --> 00:01:10,350 ‫The first webpage I referenced to you is called 34 00:01:10,350 --> 00:01:12,620 ‫the AWS Resource Type References 35 00:01:12,620 --> 00:01:14,730 ‫and this contains all the references 36 00:01:14,730 --> 00:01:16,810 ‫that are supported by CloudFormation. 37 00:01:16,810 --> 00:01:19,760 ‫And the resource naming convention is here 38 00:01:19,760 --> 00:01:21,130 ‫and if you scroll down 39 00:01:21,130 --> 00:01:24,280 ‫you can see there are a lot of resources. 40 00:01:24,280 --> 00:01:26,860 ‫Honestly you could count them, too many. 41 00:01:26,860 --> 00:01:29,130 ‫So we can see that we can create a resource 42 00:01:29,130 --> 00:01:30,510 ‫for pretty much everything. 43 00:01:30,510 --> 00:01:32,210 ‫Let's scroll down and see if there's something we know. 44 00:01:32,210 --> 00:01:33,360 ‫Yes, Auto Scaling. 45 00:01:33,360 --> 00:01:35,120 ‫We know how to create Auto Scaling group. 46 00:01:35,120 --> 00:01:37,410 ‫We're able to create Auto Scaling group, 47 00:01:37,410 --> 00:01:39,760 ‫scaling policies, launch configuration, 48 00:01:39,760 --> 00:01:42,870 ‫all through this CloudFormation resources. 49 00:01:42,870 --> 00:01:45,570 ‫If we scroll down, we're able to do code builds, 50 00:01:45,570 --> 00:01:47,930 ‫code commit, code deploy, code pipelines. 51 00:01:47,930 --> 00:01:49,390 ‫So all these things we've seen before, 52 00:01:49,390 --> 00:01:50,820 ‫we're able to do them. 53 00:01:50,820 --> 00:01:52,520 ‫And if we scroll down we can see 54 00:01:52,520 --> 00:01:54,430 ‫there is the EC2 Instances, 55 00:01:54,430 --> 00:01:56,020 ‫the elastic IP, 56 00:01:56,020 --> 00:01:57,560 ‫and then the security group. 57 00:01:57,560 --> 00:01:59,560 ‫So let's have a look at EC2 Instance 58 00:01:59,560 --> 00:02:00,560 ‫because I think that's the one 59 00:02:00,560 --> 00:02:02,800 ‫we're the most familiar with. 60 00:02:02,800 --> 00:02:07,420 ‫So the AWS EC2 Instance creates an EC2 instance. 61 00:02:07,420 --> 00:02:09,280 ‫Because that's pretty obvious. 62 00:02:09,280 --> 00:02:12,320 ‫Now basically, we can scroll down 63 00:02:12,320 --> 00:02:16,000 ‫and look at the syntax of how to declare this EC2 instance. 64 00:02:16,000 --> 00:02:17,320 ‫We have a JSON form, 65 00:02:17,320 --> 00:02:19,860 ‫which to me is a little bit unreadable, 66 00:02:19,860 --> 00:02:21,960 ‫but we scroll down and we get the YAML form, 67 00:02:21,960 --> 00:02:23,600 ‫which to me is much clearer. 68 00:02:23,600 --> 00:02:26,310 ‫So this is the YAML form for EC2 instance. 69 00:02:26,310 --> 00:02:29,047 ‫It must be of type AWS EC2 and then Instance, 70 00:02:29,047 --> 00:02:31,140 ‫and it will have some properties. 71 00:02:31,140 --> 00:02:32,580 ‫So when you create the resource, 72 00:02:32,580 --> 00:02:33,640 ‫must have a type, 73 00:02:33,640 --> 00:02:34,900 ‫must have properties. 74 00:02:34,900 --> 00:02:37,910 ‫And properties are going to be key value pairs. 75 00:02:37,910 --> 00:02:39,290 ‫So as you can see here, 76 00:02:39,290 --> 00:02:42,140 ‫you can customize a lot of things 77 00:02:42,140 --> 00:02:44,060 ‫for your EC2 instance. 78 00:02:44,060 --> 00:02:45,030 ‫For example, if you wanted to 79 00:02:45,030 --> 00:02:46,990 ‫customize the IamInstanceProfile, we click on this 80 00:02:46,990 --> 00:02:51,360 ‫and we get teleported to the documentation for that, 81 00:02:51,360 --> 00:02:53,480 ‫and it says, okay, you need a string. 82 00:02:53,480 --> 00:02:55,180 ‫It's not required, 83 00:02:55,180 --> 00:02:58,360 ‫and if you update this there's no interruptions. 84 00:02:58,360 --> 00:02:59,880 ‫That means that your EC2 instance 85 00:02:59,880 --> 00:03:02,655 ‫won't get terminated and recreated. 86 00:03:02,655 --> 00:03:05,160 ‫It will just attach the instance profile to it. 87 00:03:05,160 --> 00:03:07,240 ‫But if we change the ImageId for example, 88 00:03:07,240 --> 00:03:09,700 ‫which is also a string but not required, 89 00:03:09,700 --> 00:03:12,530 ‫then we in terms, if we update it basically 90 00:03:12,530 --> 00:03:13,890 ‫it will do a replacement. 91 00:03:13,890 --> 00:03:16,300 ‫That means that it will terminate the old instance 92 00:03:16,300 --> 00:03:18,400 ‫and replace it with a new one. 93 00:03:18,400 --> 00:03:19,900 ‫So let's go scroll back up. 94 00:03:19,900 --> 00:03:21,290 ‫And so here we understand that 95 00:03:21,290 --> 00:03:23,850 ‫there are so many things we can customize. 96 00:03:23,850 --> 00:03:25,150 ‫To know what we should specify 97 00:03:25,150 --> 00:03:28,400 ‫we should just look through the documentation. 98 00:03:28,400 --> 00:03:31,730 ‫Now if we look at what we created from before, 99 00:03:31,730 --> 00:03:34,080 ‫let's just take an example as just EC2, 100 00:03:34,080 --> 00:03:37,140 ‫we have an AvailabilityZone, an ImageId, 101 00:03:37,140 --> 00:03:38,550 ‫and an InstanceType. 102 00:03:38,550 --> 00:03:40,800 ‫And so basically I knew how to fill those 103 00:03:40,800 --> 00:03:42,970 ‫because if you click on AZ, 104 00:03:42,970 --> 00:03:45,030 ‫then you see that you have to specify 105 00:03:45,030 --> 00:03:48,340 ‫the name of the AZ where the instance is located. 106 00:03:48,340 --> 00:03:49,950 ‫And so this is quite great 107 00:03:49,950 --> 00:03:52,000 ‫and you can just keep on going with this 108 00:03:52,000 --> 00:03:53,160 ‫as much as you want. 109 00:03:53,160 --> 00:03:57,300 ‫So now we understand basically how this was created. 110 00:03:57,300 --> 00:04:00,190 ‫For fun, you could go into the resources here 111 00:04:00,190 --> 00:04:02,100 ‫and see we have an EC2 instance 112 00:04:02,100 --> 00:04:03,940 ‫but also we have an EIP 113 00:04:03,940 --> 00:04:05,520 ‫and so if we look at EIP, 114 00:04:05,520 --> 00:04:06,970 ‫so let's go back 115 00:04:06,970 --> 00:04:11,635 ‫one up and then search for EIP on this page. 116 00:04:11,635 --> 00:04:13,310 ‫There we go, we have EIP. 117 00:04:13,310 --> 00:04:16,160 ‫Here we can see that the syntax is much shorter. 118 00:04:16,160 --> 00:04:18,320 ‫We have an InstanceID and a Domain. 119 00:04:18,320 --> 00:04:21,360 ‫And so the InstanceID is what I have specified, 120 00:04:21,360 --> 00:04:23,620 ‫and the Domain I have not specified. 121 00:04:23,620 --> 00:04:26,700 ‫So here when we go back to our EIP 122 00:04:26,700 --> 00:04:27,960 ‫we can see that yeah, it makes sense. 123 00:04:27,960 --> 00:04:32,130 ‫I did specify the type to be an AWS EC2 EIP, 124 00:04:32,130 --> 00:04:33,160 ‫and in terms of properties 125 00:04:33,160 --> 00:04:35,430 ‫I only have specified the InstanceID. 126 00:04:35,430 --> 00:04:38,460 ‫We'll see what this Ref means in a second, okay? 127 00:04:38,460 --> 00:04:40,030 ‫But so the idea is that 128 00:04:40,030 --> 00:04:42,827 ‫we are able to link the documentation 129 00:04:42,827 --> 00:04:45,200 ‫to what we want to do. 130 00:04:45,200 --> 00:04:47,040 ‫And so obviously for a security group 131 00:04:47,040 --> 00:04:49,330 ‫we need to provide the security group rules 132 00:04:49,330 --> 00:04:51,070 ‫for ingress traffic 133 00:04:51,070 --> 00:04:52,690 ‫and because we can have many rules, 134 00:04:52,690 --> 00:04:54,730 ‫they're an array so let's go to 135 00:04:54,730 --> 00:04:57,780 ‫the security group documentation just to prove that point. 136 00:04:57,780 --> 00:04:59,430 ‫Security group is right here 137 00:04:59,430 --> 00:05:00,880 ‫and we go to YAML. 138 00:05:00,880 --> 00:05:03,040 ‫And if we look at SecurityGroupIngress, 139 00:05:03,040 --> 00:05:07,920 ‫we can see that is a list of Amazon EC2 group rules. 140 00:05:07,920 --> 00:05:09,820 ‫And so if we click on EC2 Group Rule 141 00:05:09,820 --> 00:05:11,520 ‫and we click on it, we go to YAML, 142 00:05:11,520 --> 00:05:14,110 ‫we get all the parameters that are available. 143 00:05:14,110 --> 00:05:16,080 ‫So going back to the syntax, 144 00:05:16,080 --> 00:05:18,110 ‫we get this little hyphen here 145 00:05:18,110 --> 00:05:19,980 ‫that defines it to be an array. 146 00:05:19,980 --> 00:05:21,840 ‫And here we get the first rule, 147 00:05:21,840 --> 00:05:24,350 ‫and here we get the second rule. 148 00:05:24,350 --> 00:05:26,720 ‫And so yeah, what we get out of this 149 00:05:26,720 --> 00:05:30,080 ‫is that everything we configure through the UI 150 00:05:30,080 --> 00:05:33,234 ‫can be written as code into your CloudFormation templates, 151 00:05:33,234 --> 00:05:35,290 ‫and this is how you know 152 00:05:35,290 --> 00:05:38,430 ‫how to redact your CloudFormation templates. 153 00:05:38,430 --> 00:05:39,890 ‫So that's it for resources. 154 00:05:39,890 --> 00:05:42,290 ‫That's honestly all you need to know. 155 00:05:42,290 --> 00:05:43,680 ‫Just remember there's a type, 156 00:05:43,680 --> 00:05:45,040 ‫and there's properties, 157 00:05:45,040 --> 00:05:47,880 ‫and all of this goes below the block called Resources. 158 00:05:47,880 --> 00:05:50,130 ‫So you need to picture there is a small indent 159 00:05:50,130 --> 00:05:53,160 ‫underneath Resources every time you declare a resource. 160 00:05:53,160 --> 00:05:55,510 ‫Now the frequently asked questions for resources. 161 00:05:55,510 --> 00:05:57,860 ‫Can I create a dynamic amount of resources? 162 00:05:57,860 --> 00:05:58,810 ‫No, you cannot. 163 00:05:58,810 --> 00:06:00,990 ‫Everything CloudFormation has to be declared, 164 00:06:00,990 --> 00:06:03,260 ‫so you cannot perform code generation. 165 00:06:03,260 --> 00:06:06,090 ‫You cannot have dynamic type of code generation. 166 00:06:06,090 --> 00:06:07,924 ‫And is every AWS Service supported? 167 00:06:07,924 --> 00:06:09,670 ‫The answer is almost. 168 00:06:09,670 --> 00:06:12,150 ‫There is only few small ones that are not there yet, 169 00:06:12,150 --> 00:06:13,470 ‫and you can work around that 170 00:06:13,470 --> 00:06:16,880 ‫using the AWS Lambda Custom Resources. 171 00:06:16,880 --> 00:06:18,240 ‫Just a little bit of trivia here. 172 00:06:18,240 --> 00:06:19,230 ‫You just need to know about it. 173 00:06:19,230 --> 00:06:22,230 ‫We will not write to Custom Resources Lambda in this course. 174 00:06:22,230 --> 00:06:23,637 ‫So that's it for resources, hope you enjoyed it. 175 00:06:23,637 --> 00:06:25,400 ‫Hope that makes more sense now, 176 00:06:25,400 --> 00:06:27,350 ‫and I will see you in the next lecture.