1 00:00:00,150 --> 00:00:02,480 ‫So, if we look at the first template 2 00:00:02,480 --> 00:00:05,160 ‫we've been using, called 0-just-ec2.yaml, 3 00:00:05,160 --> 00:00:06,780 ‫we've been seeing it's a very simple template, 4 00:00:06,780 --> 00:00:08,500 ‫and we'll look at the structure of it 5 00:00:08,500 --> 00:00:10,080 ‫in detail in the future lectures, 6 00:00:10,080 --> 00:00:11,200 ‫but just from reading it, 7 00:00:11,200 --> 00:00:13,780 ‫I think it's quite clear we are creating resources 8 00:00:13,780 --> 00:00:17,050 ‫called MyInstance of type EC2::Instance, 9 00:00:17,050 --> 00:00:18,640 ‫and in terms of properties, 10 00:00:18,640 --> 00:00:21,430 ‫we specify the AvailabilityZone, the ImageId, 11 00:00:21,430 --> 00:00:22,450 ‫so the AMI ID, 12 00:00:22,450 --> 00:00:24,390 ‫and this is why we have to use us-east, 13 00:00:24,390 --> 00:00:25,480 ‫and because we also specify 14 00:00:25,480 --> 00:00:27,810 ‫the AvailabilityZone, specifically. 15 00:00:27,810 --> 00:00:30,730 ‫And finally, the instance type t2.micro. 16 00:00:30,730 --> 00:00:33,030 ‫Now what we want to do is to update the stack, 17 00:00:33,030 --> 00:00:36,500 ‫and so I've created a second stack called ec2-with 18 00:00:36,500 --> 00:00:38,300 ‫security group called eip. 19 00:00:38,300 --> 00:00:39,223 ‫So, that means that here we're going 20 00:00:39,223 --> 00:00:41,870 ‫to have a lot more complicated template. 21 00:00:41,870 --> 00:00:43,310 ‫I won't go over it too much, 22 00:00:43,310 --> 00:00:45,750 ‫but we are adding a parameter. 23 00:00:45,750 --> 00:00:47,220 ‫We're adding, we're changing 24 00:00:47,220 --> 00:00:48,790 ‫a little bit of that EC2::Instance. 25 00:00:48,790 --> 00:00:50,440 ‫We're adding an elastic IP. 26 00:00:50,440 --> 00:00:52,300 ‫We're adding a security group 27 00:00:52,300 --> 00:00:53,960 ‫and a second security group. 28 00:00:53,960 --> 00:00:55,800 ‫So, we can expect a lot of updates. 29 00:00:55,800 --> 00:00:58,090 ‫So, lets see how we can go in CloudFormation 30 00:00:58,090 --> 00:00:58,923 ‫and apply this update. 31 00:00:58,923 --> 00:01:01,210 ‫So we're going here 32 00:01:01,210 --> 00:01:03,250 ‫and then click on updates. 33 00:01:03,250 --> 00:01:04,740 ‫And then, you have to choose how you're going to update. 34 00:01:04,740 --> 00:01:06,880 ‫You're going to use the current template, 35 00:01:06,880 --> 00:01:08,570 ‫replace it or edit it. 36 00:01:08,570 --> 00:01:10,200 ‫I'm going to replace the template, 37 00:01:10,200 --> 00:01:11,250 ‫upload a new file, 38 00:01:11,250 --> 00:01:12,540 ‫and this time, I'm going to upload the 39 00:01:12,540 --> 00:01:15,810 ‫file: 1-ec2-with-sg-eip. 40 00:01:15,810 --> 00:01:16,910 ‫So, the file is being loaded. 41 00:01:16,910 --> 00:01:18,810 ‫It's uploaded onto Amazon S3 42 00:01:18,810 --> 00:01:20,510 ‫and then, I can click on next. 43 00:01:20,510 --> 00:01:21,930 ‫Now, I get prompted 44 00:01:21,930 --> 00:01:24,530 ‫with entering the value of a parameter. 45 00:01:24,530 --> 00:01:26,310 ‫That's because we have to find a new section 46 00:01:26,310 --> 00:01:27,280 ‫in our template. 47 00:01:27,280 --> 00:01:31,040 ‫And so, we'll say: "This is a cool security group" 48 00:01:31,040 --> 00:01:32,980 ‫and this is intended to become 49 00:01:32,980 --> 00:01:34,900 ‫my security group description. 50 00:01:34,900 --> 00:01:36,310 ‫So, I click on next, 51 00:01:36,310 --> 00:01:37,660 ‫and in terms of tag options, 52 00:01:37,660 --> 00:01:39,750 ‫we'll leave the tag permissions and so on, as is. 53 00:01:39,750 --> 00:01:41,400 ‫We're not turning anything new here. 54 00:01:41,400 --> 00:01:43,130 ‫And now, we review everything. 55 00:01:43,130 --> 00:01:45,260 ‫So, the template, the parameter's values. 56 00:01:45,260 --> 00:01:47,240 ‫So, this is great, we scroll down 57 00:01:47,240 --> 00:01:49,250 ‫and at the bottom we have something called: 58 00:01:49,250 --> 00:01:51,230 ‫a change set preview. 59 00:01:51,230 --> 00:01:54,190 ‫So, this is CloudFormation figuring out 60 00:01:54,190 --> 00:01:56,350 ‫from the original template, okay. 61 00:01:56,350 --> 00:01:58,900 ‫So, from this template right here 62 00:01:58,900 --> 00:02:00,810 ‫to this new template right here, 63 00:02:00,810 --> 00:02:01,850 ‫what is the difference? 64 00:02:01,850 --> 00:02:02,960 ‫What are the differences 65 00:02:02,960 --> 00:02:04,800 ‫and what needs to change? 66 00:02:04,800 --> 00:02:06,010 ‫So, as we can see here, 67 00:02:06,010 --> 00:02:08,770 ‫an elastic IP needs to be added, 68 00:02:08,770 --> 00:02:12,090 ‫and the EC2::Instance needs to be modified, 69 00:02:12,090 --> 00:02:13,870 ‫and the replacement, true. 70 00:02:13,870 --> 00:02:17,170 ‫So that means the previous EC2::Instance will be terminated 71 00:02:17,170 --> 00:02:18,930 ‫and a new one will be created. 72 00:02:18,930 --> 00:02:20,640 ‫That's because replacement is true. 73 00:02:20,640 --> 00:02:22,170 ‫If the replacement was false, 74 00:02:22,170 --> 00:02:24,580 ‫that means the EC2::Instance will stay in place. 75 00:02:24,580 --> 00:02:26,580 ‫So, as we can see, we have three new things: 76 00:02:26,580 --> 00:02:29,290 ‫an elastic IP and two security groups, 77 00:02:29,290 --> 00:02:31,890 ‫and we have the EC2::Instance being modified 78 00:02:31,890 --> 00:02:33,180 ‫and even replaced. 79 00:02:33,180 --> 00:02:34,900 ‫So, if we are happy with this changed set, 80 00:02:34,900 --> 00:02:36,560 ‫with these changes in advance, 81 00:02:36,560 --> 00:02:38,510 ‫then we can click on update stack 82 00:02:38,510 --> 00:02:39,970 ‫and we're good to go. 83 00:02:39,970 --> 00:02:42,160 ‫So, we go back into the events, 84 00:02:42,160 --> 00:02:43,670 ‫and as we can see now, this stack 85 00:02:43,670 --> 00:02:46,430 ‫is in update_in_progress, the status, 86 00:02:46,430 --> 00:02:48,790 ‫and we need to just wait and see, what happens. 87 00:02:48,790 --> 00:02:50,600 ‫So, I'm going to refresh this page 88 00:02:50,600 --> 00:02:51,820 ‫and as we can see now, 89 00:02:51,820 --> 00:02:54,450 ‫two security groups are created for me. 90 00:02:54,450 --> 00:02:56,050 ‫So, the create is complete. 91 00:02:56,050 --> 00:02:57,870 ‫And then, if I keep on refreshing, 92 00:02:57,870 --> 00:03:00,280 ‫my EC2::Instance will be updated. 93 00:03:00,280 --> 00:03:01,580 ‫So, as we can see, 94 00:03:01,580 --> 00:03:04,610 ‫there's a new creation of a new physical EC2::Instance 95 00:03:04,610 --> 00:03:06,040 ‫because replacement was true. 96 00:03:06,040 --> 00:03:07,930 ‫So, we need to wait for this. 97 00:03:07,930 --> 00:03:10,650 ‫So if I go back to my EC2:Instance page 98 00:03:10,650 --> 00:03:12,910 ‫and refresh, I should see, yes 99 00:03:12,910 --> 00:03:15,090 ‫my second instance being created right now, 100 00:03:15,090 --> 00:03:16,470 ‫due to this update, 101 00:03:16,470 --> 00:03:18,830 ‫and so a cool thing to see is that, 102 00:03:18,830 --> 00:03:21,470 ‫the EIP is not being created yet. 103 00:03:21,470 --> 00:03:23,300 ‫The reason is, CloudFormation, 104 00:03:23,300 --> 00:03:25,150 ‫even though we haven't specified an order 105 00:03:25,150 --> 00:03:26,960 ‫of which resources should be created, 106 00:03:26,960 --> 00:03:29,520 ‫knows from the Stack template, 107 00:03:29,520 --> 00:03:31,240 ‫what to create first. 108 00:03:31,240 --> 00:03:34,550 ‫So it knew to create the first security groups, 109 00:03:34,550 --> 00:03:37,230 ‫then to update the EC2::Instance, 110 00:03:37,230 --> 00:03:40,490 ‫and finally, it will add an elastic IP. 111 00:03:40,490 --> 00:03:42,500 ‫So this is something CloudFormation does for you, 112 00:03:42,500 --> 00:03:44,290 ‫and figures out the right order 113 00:03:44,290 --> 00:03:45,920 ‫for your template creation. 114 00:03:45,920 --> 00:03:47,200 ‫So, really, really cool. 115 00:03:47,200 --> 00:03:49,050 ‫Now I need to wait for everything to be created. 116 00:03:49,050 --> 00:03:50,440 ‫So, MyInstance is now created 117 00:03:50,440 --> 00:03:52,270 ‫and now we're getting into the 118 00:03:52,270 --> 00:03:54,210 ‫elastic IP creation process. 119 00:03:54,210 --> 00:03:56,030 ‫So, the create is in progress, 120 00:03:56,030 --> 00:03:58,210 ‫and we should be done very, very soon. 121 00:03:58,210 --> 00:03:59,730 ‫And so, as soon as we're done, 122 00:03:59,730 --> 00:04:02,040 ‫well, we expect the replacement to be complete. 123 00:04:02,040 --> 00:04:04,560 ‫So, we expect our previous EC2::Instance 124 00:04:04,560 --> 00:04:06,340 ‫to be terminated. 125 00:04:06,340 --> 00:04:08,960 ‫So, lets just refresh again to see how we are. 126 00:04:08,960 --> 00:04:11,320 ‫Yes, the ESP has been created. 127 00:04:11,320 --> 00:04:13,810 ‫Now the first stack is in update complete, 128 00:04:13,810 --> 00:04:15,240 ‫clean up in progress, 129 00:04:15,240 --> 00:04:16,570 ‫and during this cleanup, 130 00:04:16,570 --> 00:04:19,400 ‫my previous EC2:Instance is being deleted. 131 00:04:19,400 --> 00:04:22,170 ‫So that means that my previous EC2::Instance in here, 132 00:04:22,170 --> 00:04:23,160 ‫should be shutting down, 133 00:04:23,160 --> 00:04:24,910 ‫and then being terminated. 134 00:04:24,910 --> 00:04:25,743 ‫So, it's really cool. 135 00:04:25,743 --> 00:04:26,870 ‫This CloudFormation template 136 00:04:26,870 --> 00:04:28,330 ‫did a lot things for us 137 00:04:28,330 --> 00:04:30,940 ‫based on just a few lines of code, 138 00:04:30,940 --> 00:04:32,470 ‫of yaml description code. 139 00:04:32,470 --> 00:04:34,290 ‫Okay, so you if go into resources now, 140 00:04:34,290 --> 00:04:35,580 ‫we can see we have a lot more things. 141 00:04:35,580 --> 00:04:37,930 ‫We have a link to the elastic IP, 142 00:04:37,930 --> 00:04:41,160 ‫the EC2::Instance and these two security groups. 143 00:04:41,160 --> 00:04:42,760 ‫And so, if we check it out, 144 00:04:42,760 --> 00:04:45,320 ‫let's just click on the EC2::Instance right now. 145 00:04:45,320 --> 00:04:48,400 ‫So, I'm taken to the EC2::Instance directly, 146 00:04:48,400 --> 00:04:50,980 ‫and what I can see is that yes, indeed, 147 00:04:50,980 --> 00:04:53,240 ‫an elastic IP is attached to it. 148 00:04:53,240 --> 00:04:54,840 ‫So, if I click on the elastic IP, 149 00:04:54,840 --> 00:04:56,670 ‫I can see it is right here, 150 00:04:56,670 --> 00:04:59,660 ‫and if I look at this elastic IP, 151 00:04:59,660 --> 00:05:01,630 ‫and look at the tags, for example, 152 00:05:01,630 --> 00:05:03,020 ‫we can see it is again, 153 00:05:03,020 --> 00:05:05,120 ‫tagged by CloudFormation. 154 00:05:05,120 --> 00:05:07,030 ‫So, just like my EC2::Instances, 155 00:05:07,030 --> 00:05:08,410 ‫this one is tagged, 156 00:05:08,410 --> 00:05:11,810 ‫and we can also have a look at our security groups. 157 00:05:11,810 --> 00:05:14,140 ‫So, here we have two security groups. 158 00:05:14,140 --> 00:05:16,580 ‫So I'm going into my two security groups 159 00:05:16,580 --> 00:05:18,330 ‫and I'm going to just look for the word: 160 00:05:18,330 --> 00:05:19,360 ‫stack, here we go, 161 00:05:19,360 --> 00:05:21,710 ‫we have two security groups created for me. 162 00:05:21,710 --> 00:05:23,950 ‫So we have our SSH security group 163 00:05:23,950 --> 00:05:26,600 ‫which contains an inbound rule 164 00:05:26,600 --> 00:05:27,940 ‫for the SSH, 165 00:05:27,940 --> 00:05:30,920 ‫and we also have a server security group 166 00:05:30,920 --> 00:05:33,490 ‫which contains a rule for Port 80. 167 00:05:33,490 --> 00:05:36,360 ‫Okay, and then finally, if we look at the description 168 00:05:36,360 --> 00:05:37,830 ‫of this security group, 169 00:05:37,830 --> 00:05:40,560 ‫it says, "This is a cool security group." 170 00:05:40,560 --> 00:05:42,300 ‫So, that means that the parameter 171 00:05:42,300 --> 00:05:44,310 ‫is somehow that we defined in here 172 00:05:44,310 --> 00:05:45,980 ‫and we gave a value to, 173 00:05:45,980 --> 00:05:49,950 ‫was applied to the value of the description 174 00:05:49,950 --> 00:05:50,860 ‫of that security group, 175 00:05:50,860 --> 00:05:52,480 ‫and we'll see how that works as well, 176 00:05:52,480 --> 00:05:54,660 ‫later on in this section. 177 00:05:54,660 --> 00:05:55,700 ‫So, very, very cool. 178 00:05:55,700 --> 00:05:58,630 ‫We've created our CloudFormation template 179 00:05:58,630 --> 00:05:59,950 ‫and updated it. 180 00:05:59,950 --> 00:06:01,310 ‫So now what we can do, 181 00:06:01,310 --> 00:06:03,060 ‫is look at deletion. 182 00:06:03,060 --> 00:06:06,290 ‫So, if we go into our CloudFormation stack, 183 00:06:06,290 --> 00:06:07,822 ‫and we're happy where were are, 184 00:06:07,822 --> 00:06:08,880 ‫one way we can do things 185 00:06:08,880 --> 00:06:11,120 ‫is go into your instances, 186 00:06:11,120 --> 00:06:12,100 ‫right-click here, 187 00:06:12,100 --> 00:06:13,550 ‫and then terminate it, 188 00:06:13,550 --> 00:06:15,510 ‫but the problem with this is that, 189 00:06:15,510 --> 00:06:17,090 ‫as soon as you do this, 190 00:06:17,090 --> 00:06:19,460 ‫then, your other things that were created 191 00:06:19,460 --> 00:06:20,980 ‫by CloudFormation still remain. 192 00:06:20,980 --> 00:06:23,070 ‫So, that includes your security groups 193 00:06:23,070 --> 00:06:24,577 ‫and that includes your EC2, 194 00:06:24,577 --> 00:06:26,670 ‫and your elastic IP address. 195 00:06:26,670 --> 00:06:27,930 ‫So, what we can do instead, 196 00:06:27,930 --> 00:06:30,250 ‫is to take this CloudFormation stack 197 00:06:30,250 --> 00:06:31,890 ‫and then we can click on delete. 198 00:06:31,890 --> 00:06:33,080 ‫And by doing so, 199 00:06:33,080 --> 00:06:36,610 ‫it will delete everything in our CloudFormation stack. 200 00:06:36,610 --> 00:06:38,300 ‫So, I'll just click on delete stack 201 00:06:38,300 --> 00:06:39,990 ‫and then, CloudFormation will go into 202 00:06:39,990 --> 00:06:41,340 ‫delete in progress. 203 00:06:41,340 --> 00:06:43,790 ‫And again, if we look at the event list, 204 00:06:43,790 --> 00:06:46,083 ‫it knows what to delete first. 205 00:06:46,083 --> 00:06:49,699 ‫So, it's going to delete the elastic IP first, 206 00:06:49,699 --> 00:06:51,070 ‫then it will go ahead 207 00:06:51,070 --> 00:06:53,030 ‫and delete the EC2::Instance. 208 00:06:53,030 --> 00:06:53,863 ‫And finally, it'll go ahead 209 00:06:53,863 --> 00:06:56,520 ‫and delete the security groups. 210 00:06:56,520 --> 00:06:58,470 ‫And that's the whole power of CloudFormation. 211 00:06:58,470 --> 00:07:01,290 ‫It is very easy to create resources, 212 00:07:01,290 --> 00:07:02,970 ‫update them, but as well 213 00:07:02,970 --> 00:07:05,570 ‫delete them, without trying to figure out 214 00:07:05,570 --> 00:07:07,090 ‫in which order to do things. 215 00:07:07,090 --> 00:07:10,050 ‫So, as soon as you go and do infrastructure AS-code. 216 00:07:10,050 --> 00:07:11,700 ‫It is extremely important for you 217 00:07:11,700 --> 00:07:14,050 ‫to understand that every resource 218 00:07:14,050 --> 00:07:16,280 ‫creation, update and delete 219 00:07:16,280 --> 00:07:18,870 ‫has to happen through CloudFormation, 220 00:07:18,870 --> 00:07:20,490 ‫and when you get the hang of it, 221 00:07:20,490 --> 00:07:22,050 ‫it becomes really, really handy 222 00:07:22,050 --> 00:07:24,860 ‫and something you will no be able to go back to. 223 00:07:24,860 --> 00:07:27,020 ‫So, I'll just wait for this stack to be deleted, 224 00:07:27,020 --> 00:07:28,510 ‫but it should work on my end 225 00:07:28,510 --> 00:07:30,460 ‫and I will see you in the next lecture.