‫Let's go and create
‫our first CloudFormation template,
‫and this template will create a simple
‫EC2 instance in our infrastructure.
‫So we then will go and add an Elastic IP to it.
‫And then we're going to add two security groups to it,
‫but not in this lecture.
‫For now, let's just forget
‫about the code syntax for CloudFormation.
‫We'll look at the structure of the files later on
‫and understand exactly how they work.
‫So we'll see how in no time, we're able
‫to get started with CloudFormation and our EC2 instances.
‫So let's go to the console.
‫Okay, so let's get started with CloudFormation.
‫So I'm gonna go in the console of CloudFormation
‫and in here I see three stacks,
‫one for CodeStar, and two for Elastic Beanstalk.
‫So we already had a glimpse of Beanstalk
‫and CloudFormation before.
‫So, as we can see, this is my prod environment stack
‫and this is my env environment stack.
‫So, I'm going to the prod one, and here in the resources,
‫we can see what was created by Beanstalk
‫so we can see 16 resources were created.
‫That includes the Auto Scaling group,
‫the launch configuration, and so on.
‫We've already done this once and we had a glimpse
‫of CloudFormation when we were in the Beanstalk console.
‫But, now, let's go to template
‫and see something really cool.
‫So, this is the template and this is the JSON,
‫this is actually horrible to read.
‫But, something we can do is click on view in designer
‫and this will take us to the CloudFormation designer.
‫And the UI is also atrocious, but here we go.
‫In this UI we are able to view
‫everything in our CloudFormation templates
‫and how they relate to one another.
‫So we can see a scaling policy and Auto Scaling group,
‫your launch configuration, your alarm,
‫and your load balancer.
‫And if I looked at the load balancer, for example,
‫I can see the configuration of that load balancer in JSON,
‫or by converting it into YAML.
‫I can see and of course, it is lost.
‫I can see here the load balancer
‫security group, for example.
‫And this is the entire configuration here.
‫Okay, so this is just an introduction to CloudFormation.
‫But for now, I'm going to close this designer,
‫get back to CloudFormation, and we are all,
‫please if you wanna do this hands on with me,
‫changing the region.
‫And we wanna go to US east one, northern Virginia.
‫The reason is, all the CloudFormation templates
‫that we're going to use in this section
‫are meant to work in north Virginia,
‫they could work somewhere else.
‫But to make sure we are on the same page, all of us,
‫please select the region US east one.
‫Okay.
‫So now let's go through the creation
‫of our first CloudFormation stack.
‫This is great, we have no stacks,
‫we're going to create a stack and with new resources,
‫which is a standard, but we could also use import in sources
‫so have existing resources into CloudFormation templates.
‫This is out of scope for the exam
‫so the only way we're going to do it right now
‫is with the new resources,
‫which is the same as clicking
‫on the create stack in the middle.
‫So now we can use a template.
‫Either template is ready, or we can use a sample template
‫or design one in the designer,
‫but right now all our templates are ready
‫so we're going to click on template is ready.
‫And then we have two ways of doing it.
‫Either we upload a template file
‫or we go and specify an Amazon S3 URL.
‫So in our case, we're going to upload a template file,
‫choose a file and choose the file called zero, just EC2.
‫And for now, we're not looking at
‫the code inside of that file.
‫And then we'll click on next.
‫We need to enter a stack name so I'll call it,
‫for example, first stack.
‫And this is just our first stack.
‫And then there are no parameters
‫so we can just click on next.
‫Here, there are no tags.
‫So that's fine.
‫We don't have any specified permissions.
‫Stack policy, rollback configuration, notification options,
‫and stack creation options are all advanced options
‫out of scope for the exam.
‫So I'm just gonna go and click on next.
‫Okay, so here we go.
‫We have our template URL right here
‫that has been uploaded onto Amazon S3,
‫and then no parameters, no stock options,
‫and we can just go all the way down
‫and click on create stack.
‫Now what this will do is that it will go ahead
‫and create our first CloudFormation stack for us.
‫And so what we can see is that we are in a different view,
‫and we are under the events tab.
‫So under the events tab, what we can see is that right now
‫we are in create in progress.
‫So whenever we create a CloudFormation stack,
‫this is going to be the first state.
‫Now if I refresh this,
‫you can see that now there are new events,
‫one called MyInstance, and the create is in progress.
‫And then there was a new event,
‫the resource creation was initiated.
‫So that means that my EC2 instance
‫is actually being created.
‫So if I want to do a sneak peek and go to the EC2 console,
‫now on the EC2 console for US east one,
‫so this is perfect, go to instances.
‫And in here, I can see my EC2 instance already running.
‫And if I look at the tags, it's very cool.
‫We can see that from the tags of that EC2 instance,
‫we are getting some CloudFormation information,
‫including the logical ID so MyInstance,
‫the stack name that it belongs to,
‫for a stack and the stack ID which is the full ARN
‫to my CloudFormation stack in here.
‫So this is perfect.
‫MyInstance is now being created and if I just refresh,
‫we are now in the create complete state
‫so that means my CloudFormation stack
‫has successfully created my EC2 instance.
‫Pretty neat, right?
‫Then we can go to resources.
‫And this shows everything that was created
‫by our CloudFormation stack so we have a direct link
‫into the EC2 console for our EC2 instance.
‫So very handy to have shortcuts like this.
‫Outputs, we currently have nothing, parameter is nothing.
‫Templates is the template that we created,
‫and that we used, sorry.
‫So this is a very simple template,
‫and we'll be able to understand it very, very soon.
‫And then finally, we can go in the designer
‫to look at our CloudFormation template
‫and see what it was creating.
‫So as we can see, and I'm going to zoom out
‫to find where it is, here's MyInstance.
‫As we can see, we have created an EC2 instance,
‫here is the corresponding YAML file.
‫And this is a very simple template
‫in the CloudFormation designer.
‫So that's it for this
‫introduction lecture to CloudFormation.
‫We have created our first CloudFormation stack
‫and it has created an EC2 instance for us,
‫and we start seeing the power of infrastructure as code.
‫That's it for me.
‫I will see you in the next lecture.