-: We are getting to the fascinating section
of CloudFormation, and CloudFormation is one
of my favorite topic in AWS.
It is something I could talk about for hours and hours,
but I'll try to make it short for you and for this exam.
So infrastructure as code, what is it?
Well currently we've been doing a hell lot of manual work.
We've been doing manual work, we've automated it
a little bit with Elastic Beanstalk,
we've set up our Pipelines to be able to automate our CICD
using CodeBuild etc. and CodePipeline.
But, all this manual work that we've been is kind of tough
to reproduce right, if we want to reproduce it
in another region, here we go again,
we click click click click everywhere
and that's a bit boring.
If you wanted to do it in another AWS account,
that would be even more painful, or even if someone went
ahead in my company and deleted everything,
for me to recreate all in my region
that would be a nightmare.
So what we'd like to have really,
is our infrastructure to be code.
And so that's a new concept and this is,
quite a new phenomenon, a new trend in the IT world
called infrastructure as code.
And so that means this code that we're going to write,
we'll be able to deploy it and it will in turn create,
update and delete our infrastructure.
This is where CloudFormation comes in.
CloudFormation is going to be a declarative way
of outlining your AWS Infrastructure, for any kind
of resources and most of them are supported.
For example, let's take a high level pseudo CloudFormation
template and we say I want a security group and I want
two EC2 machines using this group,
I want two Elastic IPs for these machines,
and I want an S3 bucket,
and by the way I want a load balancer that is connected
to these machines.
So we say in a declarative way, this is declarative,
what we want CloudFormation to do, and then CloudFormation
creates all these things for us in the right order,
with the exact configuration that we specify
and so that's kind of nice.
So benefits of CloudFormation but I guess you've already
got a good idea of them, is that number one we get our
infrastructure as code, so no resources
will be manually created, which is excellent for control.
All the code can be version controlled for example using git
so we can version control our CloudFormation which is nice.
And, all the changes to the infrastructure will
be reviewed through code review which is also very nice.
In terms of cost, CloudFormation itself is free,
but each stack that you create has an identifier,
and so you can easily track the cost of a stack,
and you can estimate the cost of your resources using
the CloudFormation template itself.
So if you want to have a savings strategy
using CloudFormation, in your development environment,
or your small AWS account, you could automate the deletion
of all the templates at 5pm and then recreate them
at 8am safely, and so because your infrastructure is code,
everything will come back up and you save a lot of money.
Other benefits of CloudFormation is going to be productivity
so you're able to destroy and recreate your infrastructure
on the fly as many times as you want.
You can automate the generation
of diagrams for your templates which is quite nice
if you create presentations.
And it's declarative programming,
so you don't need to figure out what goes before what,
in terms of ordering or orchestration,
CloudFormation tracks and does that for you.
There's a true separation of concern as well,
so you can have as many stacks as you want for many apps
and many layers, and so it's quite common to have
a VPC CloudFormation stack that creates
all the networks into the Subnet.
There is an application stack so for each application
you'll deploy, there's gonna be an application
confirmation stack and so that's something we actually see
already with Elastic Beanstalk, each time we created
an environment in Elastic Beanstalk, it went ahead
and created a CloudFormation template behind the scenes.
And so the idea is that we want to reuse
as much work out there, so we're not going to reinvent
the wheel, there's a lot of CloudFormation templates
on the web that we can already leverage.
And we can also leverage documentation which is huge,
by the way, and hard to navigate sometimes,
but on the documentation there
is everything you will ever know.
So CloudFormation, how do they work?
Well we will upload the templates in AmazonS3 behind
the scenes and CloudFormation pulls them from S3,
and so when we want to update the template we actually
can't edit a previous template, we'll see it in the next
lecture anyway, what we have to do is re upload
a new version of the template to AWS,
and then CloudFormation will do the difference
and figure out what it needs to do to update
from version one to version two.
Stacks will be identified by a name and the names
can be very long, and if you delete a stack
every single artifact, anything that was created
through the CloudFormation stack will be deleted with it.
So it's really nice because you can delete all
these resources that have been created with one click,
and so you're sure that you're not leaving anything behind.
Now to deploy CloudFormation templates, there's a manual way
in which we edit templates and do CloudFormation designer,
and using the console to input parameters,
and then the automated way which is to edit templates in
the YAML file using a text editor,
and then you use the Amazon CLI or Command Line Interface
to deploy the templates.
It's the recommended way when you want
to have some automation out of your flow,
but you're free to choose either manual or automate,
I think they're both fine.
In terms of the building blocks, you're going to learn
about those in this section quite a lot.
But there's the template components
and so we'll get the resources
and so the resources are basically the AWS resources
that we'll declare in the template
and that has to be a mandatory section,
your CloudFormation template cannot work
if you don't specify resources.
So resources can be EC2 machines, Elastic IPs,
security groups, load balancers,
name it, everything you can think of really.
And parameters, so these are dynamic inputs that
you can ask for your templates,
so users will just reference those.
Mappings which are static inputs for your templates,
static varialbles.
Outputs which is basically saying okay out
of our template we can export some stuff
and other templates can reference it.
Conditionals which are a list of conditions,
so if statements basically to control what gets created.
And Metadata overall we'll see a deep dive into all of those
so don't worry too much, you'll get to understand
them in their own time.
And for templates you get helpers and so
you can use references so you can basically link your stuff
within your template, and you can use functions
to transform data within your templates.
So high level I'll review again but I just wanted to give
you this 101.
Now this is an introduction to CloudFormation,
to me it takes over 3 hours to properly learn
and master CloudFormation, and I do teach somewhere else,
so this section is really meant for you to get a good idea
of how it works, but not drill too deep into it
because it's not needed for the exam,
so we'll be slightly less hands-on than in other sections
but still hands-on enough so you get a good idea
of how things work.
We'll learn everything anyway to answer questions for
the exam so do not worry about this,
and the exam does not require you to actually write
CloudFormation, it mostly will ask you about what feature
should you use yo perform x, y, z,
and so you should be fine.
So the exam though, expects you to understand
how to read CloudFormation, and we're going to read
a lot of CloudFormation this course.
So that was a short introduction to CloudFormation,
in the next lecture we'll go ahead with a small example
to get an idea of how it actually works
so see you in the next lecture.