1 00:00:00,600 --> 00:00:01,530 ‫Let's go and create 2 00:00:01,530 --> 00:00:03,450 ‫our first CloudFormation template, 3 00:00:03,450 --> 00:00:05,420 ‫and this template will create a simple 4 00:00:05,420 --> 00:00:08,460 ‫EC2 instance in our infrastructure. 5 00:00:08,460 --> 00:00:11,700 ‫So we then will go and add an Elastic IP to it. 6 00:00:11,700 --> 00:00:13,610 ‫And then we're going to add two security groups to it, 7 00:00:13,610 --> 00:00:15,510 ‫but not in this lecture. 8 00:00:15,510 --> 00:00:16,710 ‫For now, let's just forget 9 00:00:16,710 --> 00:00:19,270 ‫about the code syntax for CloudFormation. 10 00:00:19,270 --> 00:00:21,130 ‫We'll look at the structure of the files later on 11 00:00:21,130 --> 00:00:23,080 ‫and understand exactly how they work. 12 00:00:23,080 --> 00:00:24,700 ‫So we'll see how in no time, we're able 13 00:00:24,700 --> 00:00:27,510 ‫to get started with CloudFormation and our EC2 instances. 14 00:00:27,510 --> 00:00:28,870 ‫So let's go to the console. 15 00:00:28,870 --> 00:00:31,040 ‫Okay, so let's get started with CloudFormation. 16 00:00:31,040 --> 00:00:33,630 ‫So I'm gonna go in the console of CloudFormation 17 00:00:33,630 --> 00:00:35,160 ‫and in here I see three stacks, 18 00:00:35,160 --> 00:00:38,730 ‫one for CodeStar, and two for Elastic Beanstalk. 19 00:00:38,730 --> 00:00:40,960 ‫So we already had a glimpse of Beanstalk 20 00:00:40,960 --> 00:00:43,960 ‫and CloudFormation before. 21 00:00:43,960 --> 00:00:46,280 ‫So, as we can see, this is my prod environment stack 22 00:00:46,280 --> 00:00:48,550 ‫and this is my env environment stack. 23 00:00:48,550 --> 00:00:51,800 ‫So, I'm going to the prod one, and here in the resources, 24 00:00:51,800 --> 00:00:53,990 ‫we can see what was created by Beanstalk 25 00:00:53,990 --> 00:00:56,190 ‫so we can see 16 resources were created. 26 00:00:56,190 --> 00:00:57,890 ‫That includes the Auto Scaling group, 27 00:00:57,890 --> 00:00:59,390 ‫the launch configuration, and so on. 28 00:00:59,390 --> 00:01:01,640 ‫We've already done this once and we had a glimpse 29 00:01:01,640 --> 00:01:04,550 ‫of CloudFormation when we were in the Beanstalk console. 30 00:01:04,550 --> 00:01:06,050 ‫But, now, let's go to template 31 00:01:06,050 --> 00:01:07,510 ‫and see something really cool. 32 00:01:07,510 --> 00:01:09,273 ‫So, this is the template and this is the JSON, 33 00:01:09,273 --> 00:01:11,200 ‫this is actually horrible to read. 34 00:01:11,200 --> 00:01:14,550 ‫But, something we can do is click on view in designer 35 00:01:14,550 --> 00:01:17,780 ‫and this will take us to the CloudFormation designer. 36 00:01:17,780 --> 00:01:20,760 ‫And the UI is also atrocious, but here we go. 37 00:01:20,760 --> 00:01:22,870 ‫In this UI we are able to view 38 00:01:22,870 --> 00:01:24,990 ‫everything in our CloudFormation templates 39 00:01:24,990 --> 00:01:27,130 ‫and how they relate to one another. 40 00:01:27,130 --> 00:01:30,260 ‫So we can see a scaling policy and Auto Scaling group, 41 00:01:30,260 --> 00:01:31,820 ‫your launch configuration, your alarm, 42 00:01:31,820 --> 00:01:33,250 ‫and your load balancer. 43 00:01:33,250 --> 00:01:35,440 ‫And if I looked at the load balancer, for example, 44 00:01:35,440 --> 00:01:39,160 ‫I can see the configuration of that load balancer in JSON, 45 00:01:39,160 --> 00:01:41,400 ‫or by converting it into YAML. 46 00:01:41,400 --> 00:01:43,330 ‫I can see and of course, it is lost. 47 00:01:43,330 --> 00:01:45,610 ‫I can see here the load balancer 48 00:01:45,610 --> 00:01:47,110 ‫security group, for example. 49 00:01:47,110 --> 00:01:49,970 ‫And this is the entire configuration here. 50 00:01:49,970 --> 00:01:53,430 ‫Okay, so this is just an introduction to CloudFormation. 51 00:01:53,430 --> 00:01:56,220 ‫But for now, I'm going to close this designer, 52 00:01:56,220 --> 00:01:58,990 ‫get back to CloudFormation, and we are all, 53 00:01:58,990 --> 00:02:01,440 ‫please if you wanna do this hands on with me, 54 00:02:01,440 --> 00:02:02,670 ‫changing the region. 55 00:02:02,670 --> 00:02:06,350 ‫And we wanna go to US east one, northern Virginia. 56 00:02:06,350 --> 00:02:08,630 ‫The reason is, all the CloudFormation templates 57 00:02:08,630 --> 00:02:11,410 ‫that we're going to use in this section 58 00:02:11,410 --> 00:02:13,700 ‫are meant to work in north Virginia, 59 00:02:13,700 --> 00:02:14,730 ‫they could work somewhere else. 60 00:02:14,730 --> 00:02:17,670 ‫But to make sure we are on the same page, all of us, 61 00:02:17,670 --> 00:02:20,500 ‫please select the region US east one. 62 00:02:20,500 --> 00:02:21,333 ‫Okay. 63 00:02:21,333 --> 00:02:23,320 ‫So now let's go through the creation 64 00:02:23,320 --> 00:02:25,433 ‫of our first CloudFormation stack. 65 00:02:26,490 --> 00:02:28,070 ‫This is great, we have no stacks, 66 00:02:28,070 --> 00:02:31,550 ‫we're going to create a stack and with new resources, 67 00:02:31,550 --> 00:02:34,840 ‫which is a standard, but we could also use import in sources 68 00:02:34,840 --> 00:02:37,540 ‫so have existing resources into CloudFormation templates. 69 00:02:37,540 --> 00:02:38,700 ‫This is out of scope for the exam 70 00:02:38,700 --> 00:02:40,590 ‫so the only way we're going to do it right now 71 00:02:40,590 --> 00:02:42,660 ‫is with the new resources, 72 00:02:42,660 --> 00:02:43,900 ‫which is the same as clicking 73 00:02:43,900 --> 00:02:46,050 ‫on the create stack in the middle. 74 00:02:46,050 --> 00:02:48,270 ‫So now we can use a template. 75 00:02:48,270 --> 00:02:50,910 ‫Either template is ready, or we can use a sample template 76 00:02:50,910 --> 00:02:52,800 ‫or design one in the designer, 77 00:02:52,800 --> 00:02:54,810 ‫but right now all our templates are ready 78 00:02:54,810 --> 00:02:56,390 ‫so we're going to click on template is ready. 79 00:02:56,390 --> 00:02:58,410 ‫And then we have two ways of doing it. 80 00:02:58,410 --> 00:03:00,240 ‫Either we upload a template file 81 00:03:00,240 --> 00:03:03,490 ‫or we go and specify an Amazon S3 URL. 82 00:03:03,490 --> 00:03:05,930 ‫So in our case, we're going to upload a template file, 83 00:03:05,930 --> 00:03:09,840 ‫choose a file and choose the file called zero, just EC2. 84 00:03:09,840 --> 00:03:11,040 ‫And for now, we're not looking at 85 00:03:11,040 --> 00:03:13,030 ‫the code inside of that file. 86 00:03:13,030 --> 00:03:14,990 ‫And then we'll click on next. 87 00:03:14,990 --> 00:03:16,980 ‫We need to enter a stack name so I'll call it, 88 00:03:16,980 --> 00:03:20,470 ‫for example, first stack. 89 00:03:20,470 --> 00:03:22,410 ‫And this is just our first stack. 90 00:03:22,410 --> 00:03:23,590 ‫And then there are no parameters 91 00:03:23,590 --> 00:03:25,170 ‫so we can just click on next. 92 00:03:25,170 --> 00:03:27,010 ‫Here, there are no tags. 93 00:03:27,010 --> 00:03:28,000 ‫So that's fine. 94 00:03:28,000 --> 00:03:31,120 ‫We don't have any specified permissions. 95 00:03:31,120 --> 00:03:33,990 ‫Stack policy, rollback configuration, notification options, 96 00:03:33,990 --> 00:03:36,680 ‫and stack creation options are all advanced options 97 00:03:36,680 --> 00:03:38,020 ‫out of scope for the exam. 98 00:03:38,020 --> 00:03:39,840 ‫So I'm just gonna go and click on next. 99 00:03:39,840 --> 00:03:41,800 ‫Okay, so here we go. 100 00:03:41,800 --> 00:03:44,050 ‫We have our template URL right here 101 00:03:44,050 --> 00:03:46,370 ‫that has been uploaded onto Amazon S3, 102 00:03:46,370 --> 00:03:49,010 ‫and then no parameters, no stock options, 103 00:03:49,010 --> 00:03:50,830 ‫and we can just go all the way down 104 00:03:50,830 --> 00:03:53,250 ‫and click on create stack. 105 00:03:53,250 --> 00:03:55,060 ‫Now what this will do is that it will go ahead 106 00:03:55,060 --> 00:03:58,250 ‫and create our first CloudFormation stack for us. 107 00:03:58,250 --> 00:04:01,340 ‫And so what we can see is that we are in a different view, 108 00:04:01,340 --> 00:04:03,710 ‫and we are under the events tab. 109 00:04:03,710 --> 00:04:06,880 ‫So under the events tab, what we can see is that right now 110 00:04:06,880 --> 00:04:08,560 ‫we are in create in progress. 111 00:04:08,560 --> 00:04:11,510 ‫So whenever we create a CloudFormation stack, 112 00:04:11,510 --> 00:04:13,520 ‫this is going to be the first state. 113 00:04:13,520 --> 00:04:14,840 ‫Now if I refresh this, 114 00:04:14,840 --> 00:04:17,040 ‫you can see that now there are new events, 115 00:04:17,040 --> 00:04:20,240 ‫one called MyInstance, and the create is in progress. 116 00:04:20,240 --> 00:04:22,250 ‫And then there was a new event, 117 00:04:22,250 --> 00:04:24,260 ‫the resource creation was initiated. 118 00:04:24,260 --> 00:04:26,520 ‫So that means that my EC2 instance 119 00:04:26,520 --> 00:04:28,190 ‫is actually being created. 120 00:04:28,190 --> 00:04:31,820 ‫So if I want to do a sneak peek and go to the EC2 console, 121 00:04:31,820 --> 00:04:34,200 ‫now on the EC2 console for US east one, 122 00:04:34,200 --> 00:04:37,040 ‫so this is perfect, go to instances. 123 00:04:37,040 --> 00:04:41,130 ‫And in here, I can see my EC2 instance already running. 124 00:04:41,130 --> 00:04:43,180 ‫And if I look at the tags, it's very cool. 125 00:04:43,180 --> 00:04:45,900 ‫We can see that from the tags of that EC2 instance, 126 00:04:45,900 --> 00:04:48,120 ‫we are getting some CloudFormation information, 127 00:04:48,120 --> 00:04:50,630 ‫including the logical ID so MyInstance, 128 00:04:50,630 --> 00:04:52,230 ‫the stack name that it belongs to, 129 00:04:52,230 --> 00:04:55,340 ‫for a stack and the stack ID which is the full ARN 130 00:04:55,340 --> 00:04:58,030 ‫to my CloudFormation stack in here. 131 00:04:58,030 --> 00:04:58,863 ‫So this is perfect. 132 00:04:58,863 --> 00:05:02,180 ‫MyInstance is now being created and if I just refresh, 133 00:05:02,180 --> 00:05:04,360 ‫we are now in the create complete state 134 00:05:04,360 --> 00:05:06,160 ‫so that means my CloudFormation stack 135 00:05:06,160 --> 00:05:09,130 ‫has successfully created my EC2 instance. 136 00:05:09,130 --> 00:05:10,590 ‫Pretty neat, right? 137 00:05:10,590 --> 00:05:12,140 ‫Then we can go to resources. 138 00:05:12,140 --> 00:05:14,540 ‫And this shows everything that was created 139 00:05:14,540 --> 00:05:17,520 ‫by our CloudFormation stack so we have a direct link 140 00:05:17,520 --> 00:05:21,100 ‫into the EC2 console for our EC2 instance. 141 00:05:21,100 --> 00:05:23,540 ‫So very handy to have shortcuts like this. 142 00:05:23,540 --> 00:05:26,600 ‫Outputs, we currently have nothing, parameter is nothing. 143 00:05:26,600 --> 00:05:29,300 ‫Templates is the template that we created, 144 00:05:29,300 --> 00:05:30,420 ‫and that we used, sorry. 145 00:05:30,420 --> 00:05:32,240 ‫So this is a very simple template, 146 00:05:32,240 --> 00:05:35,360 ‫and we'll be able to understand it very, very soon. 147 00:05:35,360 --> 00:05:37,880 ‫And then finally, we can go in the designer 148 00:05:37,880 --> 00:05:40,130 ‫to look at our CloudFormation template 149 00:05:40,130 --> 00:05:41,620 ‫and see what it was creating. 150 00:05:41,620 --> 00:05:43,660 ‫So as we can see, and I'm going to zoom out 151 00:05:43,660 --> 00:05:46,050 ‫to find where it is, here's MyInstance. 152 00:05:46,050 --> 00:05:48,460 ‫As we can see, we have created an EC2 instance, 153 00:05:48,460 --> 00:05:50,400 ‫here is the corresponding YAML file. 154 00:05:50,400 --> 00:05:51,930 ‫And this is a very simple template 155 00:05:51,930 --> 00:05:53,570 ‫in the CloudFormation designer. 156 00:05:53,570 --> 00:05:55,110 ‫So that's it for this 157 00:05:55,110 --> 00:05:57,120 ‫introduction lecture to CloudFormation. 158 00:05:57,120 --> 00:06:00,180 ‫We have created our first CloudFormation stack 159 00:06:00,180 --> 00:06:02,490 ‫and it has created an EC2 instance for us, 160 00:06:02,490 --> 00:06:06,010 ‫and we start seeing the power of infrastructure as code. 161 00:06:06,010 --> 00:06:06,843 ‫That's it for me. 162 00:06:06,843 --> 00:06:08,500 ‫I will see you in the next lecture.