- Now let's run through a demo
of creating resources with AWS Cloudformation.
Here we are back at the console.
From here, from the dashboard,
I'm gonna click on Cloud Formation.
From here you can see we don't have any stacks yet.
Before we get into creating a stack,
I want to show you a template that I've created
that will create a VPC,
subnets,
an internet gateway,
and a few other things.
So here's our template.
Again, we have our parameters,
which will specify some CIDR ranges four our VPC
and for various subnets.
And then you can see the rest of the template
is dedicated to creating resources.
We have route tables,
network ACLs.
We have ACL entries.
A little bit farther down here,
here's our VPC.
You can see we're referencing
the CIDR parameter.
We're also going to tag this
and reference the stack name that we give our stack.
And you can see this template does get fairly involved.
There's quite a bit going on here.
There's quite a number of resources
that are being created and managed by this template.
I would recommend looking for tools.
There are a number of tools out there
that will help create these templates for you.
One of them is, of course,
the designer within Cloudformation.
We can use the designer which is just a rich UI
and drag and drop tool set.
There are other services out there such as VisualOps
just to name one.
And these tools can allow you drag and drop
different resources
and they will create the template for you.
So, a template as rich as this one and as complex
can be challenging to start writing from scratch
just because there's a lot of room for syntactical error.
But as long as you're using an appropriate editor
that can highlight errors like this
by causing a syntax error
we'd get a highlight there,
then that does make it a lot easier.
So, from here, I'm going to just say create a new stack.
I'm going to upload one.
I'm gonna choose my VPC.JSON.
I'm gonna click Next.
And of course it'll ask us for a stack name.
I'm gonna call this one AWS
live ...
lessons ...
VPC.
And this one is going to create ...
a VPC
and it's gonna give us three private subnets
and three public subnets.
Typo there in my description, but that's okay.
As long as my parameters are named correctly,
that's really what matters in this particular case.
So, I'm going to choose,
for this example I'm gonna choose 10.10.0.0/16.
And for my private subnets,
I'm gonna go with 10.0.0/24,
10.1.0/24,
and 10.10.2.0/24.
So those three ranges will be my private subnets.
I'm gonna copy those.
This is just a comma delimited list.
So my private subnets need to be three different ranges.
So I left off at two.
So here I can do 10.10.3,
10.10.4,
and 10.10.5.
Just want to glance at that real quick and make sure
I'm not missing any periods or slashes or whatnot.
Alright, I'm gonna click next.
And here I have the opportunity to tag my resources.
So I might want to add like an environment tag
such as dev, stage, production,
so on and so forth.
I might want to call add a name tag.
Or maybe I want to call this one networking.
Now I do want to point out something
under the advanced tab.
We do have the option to get notifications
from this Cloudformation stack
if it were to fail or succeed,
we could get those by leveraging the
Amazon Simple Notification Service.
Another important point here is
the Rollback on Failure.
This defaults to Yes.
So let's say that we get 90% of the way through.
We've created nine out of the 10 resources.
And right there on the 10th resource there is an error
that prevents that resource from being created
and as a result prevents the entire stack from completing.
Rollback on Failure, if we have this checked as Yes,
that would essentially stop the stack creation
and then go back and delete all of those nine resources
that were successful.
And it would roll it back all the way to the beginning
as if nothing ever happened.
Sometimes you want that,
but in other cases,
by having it Rollback on Failure,
if there was a problem,
and then it rolled back and deleted that resource,
that could make it difficult to troubleshoot
what the problem was.
So a lot of times I will say no,
don't Rollback on Failure.
Just stop there, leave everything in place
so that I have an opportunity to go in
and do some troubleshooting.
So, from there we'll click next
just to review this real quick.
We have our stack name.
We have the CIDR range of our VPC.
We have our six private subnet ranges.
And I'm gonna go ahead and hit Create.
You can see our stack is now actually creating.
On the events tab we can see things coming in
in pretty much real time
as different resources are being created.
You can see I've got an internet gateway,
a VPC being initialized.
There we go,
our gateway and our VPC are both complete.
Some subnets and route tables and security groups
that still need to be created.
So we're still waiting on those.
I'm gonna hit refresh.
You can see that.
Here are all of our network ACL entries,
our routes,
a few other things have completed.
While that's going I can show you a few other things,
like the template itself.
We can see the template that's being used.
We can see the parameters that we entered.
We can see the tags that we applied.
We can also go back here and see the resources.
These are all of the various resources
that are being managed under the umbrella
of this particular stack.
And like I mentioned before,
all of these things,
if we were to do this manually,
look at all these resources.
It would take time.
It would take a lot of time.
Even just to do it once,
let alone to do it multiple times
across multiple environments or multiple regions.
And then of course we have the human error factor.
So, you can see that,
even just with a simple template like this,
that the Cloudformation service makes managing
all of these resources a whole lot easier.
At some point if we decide that
we no longer need these resources,
we can just simply highlight this stack,
go up here and say delete.
And then it will handle the deletion
of all of those resources for us.
And there we go.
Our stack has gone into the create complete status.
We can see here that all of our resources
have completed their creation.
We can see here are all of our resources
and now of course if I were to go back to,
let's go back to VPC
and I'll show you that here we are.
We have the new VPC that was just created,
the 10.10 range.
And you can see that we have three private
and three public ...
subnets.
We have some route tables.
We have an internet gateway.
We also have some network ACLs for public traffic
and for back-end private traffic
along with corresponding network ACL entries.
So, again,
these were a lot of individual resources
that were created very quickly and very easily
by leveraging the Cloudformation service.
So just to go back real quick
and review that.
All we did was,
you know we created a stack,
we uploaded our template,
added a few parameters,
and allowed the Cloudformation engine
to build the resources that were specified in this template.
So that is creating resources with AWS Cloudformation.