1 00:00:00,170 --> 00:00:02,081 ‫Okay, so I'm going to give you 2 00:00:02,081 --> 00:00:03,490 ‫a short introduction to CloudFormation, 3 00:00:03,490 --> 00:00:06,730 ‫because it's so important to see how this service works. 4 00:00:06,730 --> 00:00:09,620 ‫So in CloudFormation we're going to create a stack 5 00:00:09,620 --> 00:00:11,454 ‫and then you have to provide a stack, templates. 6 00:00:11,454 --> 00:00:14,840 ‫So I wanna make sure that before you create a stack, 7 00:00:14,840 --> 00:00:16,070 ‫the stack template I have to use 8 00:00:16,070 --> 00:00:18,620 ‫has to be used in US East 1, 9 00:00:18,620 --> 00:00:20,350 ‫so please click on the region, 10 00:00:20,350 --> 00:00:23,480 ‫and click on US East Northern Virginia, US East 1, 11 00:00:23,480 --> 00:00:25,100 ‫otherwise things will not work for you 12 00:00:25,100 --> 00:00:25,933 ‫and you will get an error. 13 00:00:25,933 --> 00:00:29,184 ‫So please everyone, go to the US East Northern Virginia, 14 00:00:29,184 --> 00:00:31,040 ‫US East 1 region. 15 00:00:31,040 --> 00:00:34,360 ‫Okay, so next we have to create a stack through a template, 16 00:00:34,360 --> 00:00:36,080 ‫so we can use some sample templates, 17 00:00:36,080 --> 00:00:37,680 ‫or even create one in designer, 18 00:00:37,680 --> 00:00:39,450 ‫but I already have a template that is ready for us. 19 00:00:39,450 --> 00:00:41,340 ‫So we're going to use the ready to make templates, 20 00:00:41,340 --> 00:00:43,290 ‫and then we can either say that the template 21 00:00:43,290 --> 00:00:45,238 ‫is in Amazon S3, or we can upload it. 22 00:00:45,238 --> 00:00:46,137 ‫And we are going to upload it, 23 00:00:46,137 --> 00:00:48,625 ‫so I'm going to click on upload a file, 24 00:00:48,625 --> 00:00:52,490 ‫and within the code I will choose CloudFormation. 25 00:00:52,490 --> 00:00:55,633 ‫And within it I will choose 0-just-ec2. 26 00:00:56,490 --> 00:00:59,007 ‫This CloudFormation template is going to create 27 00:00:59,007 --> 00:01:00,610 ‫and EC2 Instance for us. 28 00:01:00,610 --> 00:01:02,999 ‫If you wanted to look at what is within that template, 29 00:01:02,999 --> 00:01:05,360 ‫it is not necessary to know how this works, 30 00:01:05,360 --> 00:01:07,320 ‫but as you can see it's quite easy to read. 31 00:01:07,320 --> 00:01:09,190 ‫We are going to create resources, 32 00:01:09,190 --> 00:01:11,050 ‫one is going to be called My Instance, 33 00:01:11,050 --> 00:01:13,300 ‫the type of it is an EC2 Instance 34 00:01:13,300 --> 00:01:15,760 ‫and then you define some properties about that EC2 Instance. 35 00:01:15,760 --> 00:01:17,220 ‫For example the availability zone, 36 00:01:17,220 --> 00:01:18,480 ‫UE East 1a, 37 00:01:18,480 --> 00:01:19,696 ‫the image ID so the AMI ID, 38 00:01:19,696 --> 00:01:22,750 ‫and the instance type, t2 micro. 39 00:01:22,750 --> 00:01:23,583 ‫And that's it. 40 00:01:23,583 --> 00:01:26,070 ‫This should create for us an EC2 Instance. 41 00:01:26,070 --> 00:01:28,260 ‫So we are uploading this file, this is good, 42 00:01:28,260 --> 00:01:30,200 ‫then we click on View in Designer 43 00:01:30,200 --> 00:01:33,100 ‫if you want to see what this template look like 44 00:01:33,100 --> 00:01:35,857 ‫in the designer, in the graphical way. 45 00:01:35,857 --> 00:01:39,100 ‫As we can see, very quickly as soon as I zoom out. 46 00:01:39,100 --> 00:01:40,800 ‫This is a very simple Instance, 47 00:01:40,800 --> 00:01:42,230 ‫just an EC2 Instance. 48 00:01:42,230 --> 00:01:43,780 ‫And it is alone right now. 49 00:01:43,780 --> 00:01:46,280 ‫Okay, I will click on next 50 00:01:46,280 --> 00:01:49,047 ‫and the I will call it DemoCloudFormation. 51 00:01:50,320 --> 00:01:51,290 ‫Okay, great. 52 00:01:51,290 --> 00:01:53,370 ‫Next you're able to set some parameters but for now 53 00:01:53,370 --> 00:01:54,701 ‫we don't have one in our template so there 54 00:01:54,701 --> 00:01:56,720 ‫is no input here. 55 00:01:56,720 --> 00:01:57,770 ‫I will click on next, 56 00:01:57,770 --> 00:02:00,593 ‫we could tag it, I will call it Name DemoCF 57 00:02:02,330 --> 00:02:03,840 ‫and I will scroll down. 58 00:02:03,840 --> 00:02:05,720 ‫We don't need to worry about these options, 59 00:02:05,720 --> 00:02:08,030 ‫we'll click on next and then you can see here 60 00:02:08,030 --> 00:02:09,610 ‫that you can estimate the cost. 61 00:02:09,610 --> 00:02:12,010 ‫I don't know how long this link is going to be working 62 00:02:12,010 --> 00:02:16,200 ‫because the Simple Monthly Calculator is going away, 63 00:02:16,200 --> 00:02:19,210 ‫but right now you can click on estimate cost 64 00:02:19,210 --> 00:02:20,060 ‫if you wanted to. 65 00:02:21,270 --> 00:02:23,420 ‫So we review everything, I will scroll down 66 00:02:23,420 --> 00:02:25,550 ‫and then I will click on create stack. 67 00:02:25,550 --> 00:02:28,600 ‫And as you can see what I did is that I uploaded 68 00:02:28,600 --> 00:02:30,920 ‫a template so the template is here, 69 00:02:30,920 --> 00:02:32,890 ‫this is just some lines of codes. 70 00:02:32,890 --> 00:02:35,580 ‫And this template is actually going to be used 71 00:02:35,580 --> 00:02:37,530 ‫to create an EC2 Instance. 72 00:02:37,530 --> 00:02:39,480 ‫So this is why CloudFormation is called 73 00:02:39,480 --> 00:02:41,400 ‫Infrastructure as Code. 74 00:02:41,400 --> 00:02:44,160 ‫So if we go to events we can see all the events 75 00:02:44,160 --> 00:02:46,050 ‫that are happening for our stack creation. 76 00:02:46,050 --> 00:02:48,690 ‫And as we can see MyInstance is now in 77 00:02:48,690 --> 00:02:50,900 ‫create-in-progress, and so that means that the 78 00:02:50,900 --> 00:02:53,310 ‫EC2 Instance is now being created. 79 00:02:53,310 --> 00:02:56,060 ‫We can verify this by going into the EC2 console. 80 00:02:56,060 --> 00:02:57,710 ‫So let's go into the EC2 console, 81 00:02:58,810 --> 00:03:00,870 ‫and as we can see in the EC2 console, 82 00:03:00,870 --> 00:03:04,263 ‫I am also in the US East Northern Virginia region. 83 00:03:05,290 --> 00:03:07,960 ‫Then you click on Instances and you will see that 84 00:03:07,960 --> 00:03:10,730 ‫yes this EC2 Instance was created for me, 85 00:03:10,730 --> 00:03:14,040 ‫the name is DemoCF, the type is T2 micro, 86 00:03:14,040 --> 00:03:16,270 ‫and the AMI ID is the one we specified. 87 00:03:16,270 --> 00:03:19,340 ‫As well as the availability zone which is US East 1a. 88 00:03:19,340 --> 00:03:23,150 ‫So whatever we had specified in our template is 89 00:03:23,150 --> 00:03:26,300 ‫what has been created in AWS. 90 00:03:26,300 --> 00:03:29,061 ‫So when we're done we get into the create-complete status. 91 00:03:29,061 --> 00:03:31,460 ‫And now if you look at the stack info, it is 92 00:03:31,460 --> 00:03:33,290 ‫create-complete and it fully done. 93 00:03:33,290 --> 00:03:35,630 ‫So now we can use that EC2 Instance, 94 00:03:35,630 --> 00:03:37,080 ‫and do whatever we want with it. 95 00:03:37,080 --> 00:03:39,850 ‫And this is the power of Infrastructure as Code. 96 00:03:39,850 --> 00:03:42,080 ‫So these are our confirmation templates, 97 00:03:42,080 --> 00:03:45,820 ‫but on top of creating one you can update it. 98 00:03:45,820 --> 00:03:47,090 ‫If I go to update, 99 00:03:47,090 --> 00:03:48,983 ‫I'm able to replace the current template, 100 00:03:48,983 --> 00:03:51,480 ‫and upload a new one. 101 00:03:51,480 --> 00:03:52,740 ‫And in this case I will be choosing 102 00:03:52,740 --> 00:03:56,840 ‫1-ec2-with-sg-eip.yaml, 103 00:03:56,840 --> 00:03:59,090 ‫and this template is a little bit more complete. 104 00:03:59,090 --> 00:04:01,580 ‫Because if we have a look at it, we have more stuff. 105 00:04:01,580 --> 00:04:02,910 ‫We have some parameters, 106 00:04:02,910 --> 00:04:05,990 ‫we have some resources which contains my EC2 Instance 107 00:04:05,990 --> 00:04:08,220 ‫but in this now there is security groups attached 108 00:04:08,220 --> 00:04:09,580 ‫to my EC2 Instance. 109 00:04:09,580 --> 00:04:11,510 ‫I defined an Elastic IP, 110 00:04:11,510 --> 00:04:13,620 ‫I defined two security groups 111 00:04:13,620 --> 00:04:15,710 ‫and their security group rules. 112 00:04:15,710 --> 00:04:17,660 ‫These security groups are going to be attached 113 00:04:17,660 --> 00:04:19,780 ‫to my EC2 Instance. 114 00:04:19,780 --> 00:04:21,630 ‫So this template is more complicated, 115 00:04:21,630 --> 00:04:23,810 ‫but now we have four kind of resources. 116 00:04:23,810 --> 00:04:25,910 ‫CloudFormation is smart enough to figure out what 117 00:04:25,910 --> 00:04:28,630 ‫to do with a template and how to create things 118 00:04:28,630 --> 00:04:29,960 ‫in the right order. 119 00:04:29,960 --> 00:04:30,930 ‫Let's have a look. 120 00:04:30,930 --> 00:04:32,600 ‫I'm going to click on Next, 121 00:04:32,600 --> 00:04:35,240 ‫and now we want to specify the Security Group Description, 122 00:04:35,240 --> 00:04:40,240 ‫so Demo Security Group Description through CloudFormation. 123 00:04:41,720 --> 00:04:42,553 ‫As you can see, 124 00:04:42,553 --> 00:04:44,660 ‫we can enter whatever we want in the parameters. 125 00:04:44,660 --> 00:04:46,540 ‫I will click on next, and maybe it's going to be too long 126 00:04:46,540 --> 00:04:49,550 ‫so I'll just do Demo Security Group just to be safe. 127 00:04:49,550 --> 00:04:52,060 ‫I will click on next, I can change the tags 128 00:04:52,060 --> 00:04:53,200 ‫but I will keep the as is. 129 00:04:53,200 --> 00:04:54,572 ‫We'll scroll down click on next, 130 00:04:54,572 --> 00:04:57,780 ‫and then I will scroll down again 131 00:04:57,780 --> 00:04:59,950 ‫and as we can see in the very bottom. 132 00:04:59,950 --> 00:05:02,010 ‫There is something called a change set. 133 00:05:02,010 --> 00:05:04,600 ‫Now a change set is what CloudFormation will do 134 00:05:04,600 --> 00:05:06,351 ‫if we apply this stack. 135 00:05:06,351 --> 00:05:09,483 ‫As we can see it will add an Elastic IP, 136 00:05:09,483 --> 00:05:12,820 ‫it will add two security groups, okay, 137 00:05:12,820 --> 00:05:15,370 ‫and for the instance it will modify it. 138 00:05:15,370 --> 00:05:18,060 ‫And to modify it, it will do replacement True 139 00:05:18,060 --> 00:05:20,843 ‫so that means that the previous instance is 140 00:05:20,843 --> 00:05:21,800 ‫going to be terminated and a new instance 141 00:05:21,800 --> 00:05:23,564 ‫will be created with the right configuration. 142 00:05:23,564 --> 00:05:26,740 ‫In this example, CloudFormation will have to destroy 143 00:05:26,740 --> 00:05:28,510 ‫and terminate the previous instance. 144 00:05:28,510 --> 00:05:30,050 ‫Something that's good to know. 145 00:05:30,050 --> 00:05:31,910 ‫Okay, so we're happy with these changes, 146 00:05:31,910 --> 00:05:33,940 ‫so let's go ahead and update the stack. 147 00:05:33,940 --> 00:05:36,460 ‫And now we are into update-in-progress. 148 00:05:36,460 --> 00:05:39,460 ‫And so CloudFormation will do behind the scenes 149 00:05:39,460 --> 00:05:42,502 ‫all the necessary changes in our AWS Cloud, 150 00:05:42,502 --> 00:05:45,995 ‫to get to the end state we have specified through the 151 00:05:45,995 --> 00:05:47,426 ‫templates. 152 00:05:47,426 --> 00:05:49,890 ‫In the meantime we can do this template in designer, 153 00:05:49,890 --> 00:05:52,433 ‫to see that it's a little bit more complete. 154 00:05:52,433 --> 00:05:56,843 ‫In this example, we have MyInstance, 155 00:05:56,843 --> 00:05:58,575 ‫connected to an Elastic IP, 156 00:05:58,575 --> 00:06:01,080 ‫and connected to two security groups. 157 00:06:01,080 --> 00:06:03,120 ‫And this is again, a nice way to visualize this. 158 00:06:03,120 --> 00:06:06,360 ‫Back into our CloudFormation template, 159 00:06:06,360 --> 00:06:08,100 ‫let's have a look at the other tabs, 160 00:06:08,100 --> 00:06:11,524 ‫so parameters is what we had as the value of the parameter. 161 00:06:11,524 --> 00:06:15,207 ‫Resources is what is getting created by our CloudFormation 162 00:06:15,207 --> 00:06:17,580 ‫template, so as we can see so far, 163 00:06:17,580 --> 00:06:20,580 ‫two security groups have been created and 164 00:06:20,580 --> 00:06:22,450 ‫MyInstance is in update-in-progress. 165 00:06:22,450 --> 00:06:25,017 ‫I will need to wait a little bit. 166 00:06:25,017 --> 00:06:27,330 ‫We are waiting for the events, 167 00:06:27,330 --> 00:06:29,700 ‫for my Elastic IP to also be created, 168 00:06:29,700 --> 00:06:30,910 ‫and it happens right now, 169 00:06:30,910 --> 00:06:32,460 ‫so create is in progress. 170 00:06:32,460 --> 00:06:34,433 ‫It is going to be very very quick. 171 00:06:34,433 --> 00:06:36,470 ‫As soon as I finish refreshing this, 172 00:06:36,470 --> 00:06:38,430 ‫we can see in the resources that now 173 00:06:38,430 --> 00:06:40,040 ‫four resources have been created, 174 00:06:40,040 --> 00:06:42,300 ‫and so my template is almost done. 175 00:06:42,300 --> 00:06:45,060 ‫Back into my EC2 console, if I refresh this, 176 00:06:45,060 --> 00:06:47,360 ‫I can see that now I have two EC2 Instances. 177 00:06:47,360 --> 00:06:49,410 ‫One that was created from before, and 178 00:06:49,410 --> 00:06:51,380 ‫one that is created right now. 179 00:06:51,380 --> 00:06:53,940 ‫And because we only need one EC2 Instance, 180 00:06:53,940 --> 00:06:56,697 ‫then expect the other one to be terminated very very soon 181 00:06:56,697 --> 00:06:59,230 ‫by CloudFormation. 182 00:06:59,230 --> 00:07:01,030 ‫If I refresh we'll see this in seconds so the 183 00:07:01,030 --> 00:07:04,338 ‫Elastic IP is now being fully completed. 184 00:07:04,338 --> 00:07:07,570 ‫If I go to events, now there's a cleanup in progress, 185 00:07:07,570 --> 00:07:09,604 ‫and the cleanup is actually going to terminate 186 00:07:09,604 --> 00:07:12,440 ‫the other EC2 Instance I had created. 187 00:07:12,440 --> 00:07:14,310 ‫Back into these two instances, 188 00:07:14,310 --> 00:07:16,230 ‫I will refresh this and now these other 189 00:07:16,230 --> 00:07:17,690 ‫instance is shutting down. 190 00:07:17,690 --> 00:07:20,400 ‫As you can see, I did nothing but write code, 191 00:07:20,400 --> 00:07:23,000 ‫and CloudFormation figured out exactly what to do, 192 00:07:23,000 --> 00:07:24,430 ‫what to create in the right order, 193 00:07:24,430 --> 00:07:27,860 ‫when to delete EC2 Instances and so on. 194 00:07:27,860 --> 00:07:31,060 ‫That's the really, the big magic of CloudFormation. 195 00:07:31,060 --> 00:07:33,920 ‫As we can see, instances have been created, 196 00:07:33,920 --> 00:07:36,770 ‫if I go to tags they're tagged with a name I gave it, 197 00:07:36,770 --> 00:07:38,840 ‫but also they also get some CloudFormation tags 198 00:07:38,840 --> 00:07:40,030 ‫automatically. 199 00:07:40,030 --> 00:07:43,883 ‫If I go to my security groups in here, 200 00:07:43,883 --> 00:07:46,480 ‫I will see the security groups created by CloudFormation, 201 00:07:46,480 --> 00:07:48,950 ‫there are two right here and if I go to 202 00:07:48,950 --> 00:07:49,783 ‫Elastic IP, 203 00:07:49,783 --> 00:07:51,280 ‫we haven't really seen Elastic IP but it is 204 00:07:51,280 --> 00:07:52,860 ‫a static public IP. 205 00:07:52,860 --> 00:07:56,060 ‫We can see one has been created right here. 206 00:07:56,060 --> 00:07:59,610 ‫CloudFormation really allowed us to have all these 207 00:07:59,610 --> 00:08:01,860 ‫things created for me, automatically, 208 00:08:01,860 --> 00:08:03,390 ‫and now the update is complete 209 00:08:03,390 --> 00:08:04,950 ‫for my CloudFormation templates. 210 00:08:04,950 --> 00:08:06,320 ‫And what about cleanup? 211 00:08:06,320 --> 00:08:07,470 ‫Well, as you can expect, 212 00:08:07,470 --> 00:08:09,170 ‫CloudFormation can cleanup after itself, 213 00:08:09,170 --> 00:08:12,010 ‫so we don't need to go and delete things manually 214 00:08:12,010 --> 00:08:13,500 ‫in the EC2 console. 215 00:08:13,500 --> 00:08:14,333 ‫No, no, no. 216 00:08:14,333 --> 00:08:17,140 ‫Instead what we can do is to get the stack, 217 00:08:17,140 --> 00:08:19,310 ‫and then you click on delete and this will delete 218 00:08:19,310 --> 00:08:21,730 ‫all the resources associated with a stack. 219 00:08:21,730 --> 00:08:23,350 ‫So I'll click on delete, 220 00:08:23,350 --> 00:08:24,610 ‫and now the delete is initiated, 221 00:08:24,610 --> 00:08:26,600 ‫and again CloudFormation will figure out 222 00:08:26,600 --> 00:08:29,434 ‫in which order to delete these stack elements 223 00:08:29,434 --> 00:08:31,270 ‫and resources. 224 00:08:31,270 --> 00:08:33,160 ‫And this is great because we can just clean up after 225 00:08:33,160 --> 00:08:35,850 ‫ourselves and will be done for this hands-on. 226 00:08:35,850 --> 00:08:37,450 ‫So, all in all, to summarize 227 00:08:37,450 --> 00:08:40,420 ‫CloudFormation is a really easy way to define templates 228 00:08:40,420 --> 00:08:42,770 ‫and resources and Infrastructure as Code. 229 00:08:42,770 --> 00:08:45,700 ‫And CloudFormation allows you to take the same template 230 00:08:45,700 --> 00:08:48,165 ‫and if it's well written you can deploy it to many 231 00:08:48,165 --> 00:08:51,280 ‫AWS regions or many AWS accounts. 232 00:08:51,280 --> 00:08:54,290 ‫And that makes it, really a base foundation 233 00:08:54,290 --> 00:08:58,130 ‫for so many other types of infrastructure on AWS. 234 00:08:58,130 --> 00:08:59,040 ‫So I hope you like this lecture, 235 00:08:59,040 --> 00:09:00,140 ‫I hope that makes sense, 236 00:09:00,140 --> 00:09:02,090 ‫and I will see you in the next lecture.