- So here, let's review a demo of routing
our subnets to the Internet.
Again, back in the console,
I'm going to make sure that we are filtered by the VPC
that we're working with, in this case the 10.2 slash 16.
From here, I'm going to go to my Route Tables.
And you will see that we have one route table.
This is what we call the main or the default route table.
You'll notice that it is, where we say subnet associations,
it says zero subnets are explicitly associated.
That means that these particular subnets,
because they don't have a route table directly associated,
that they are falling back to this route table
as their default.
That's what makes this the main route table.
So, what I want to do,
if you'll notice here that the route that we have is local,
and what I like to do is keep the main route table,
the fallback route table private,
so that we don't end up inadvertently giving
public internet access to subnets without realizing it.
So, the first thing that I want to do is,
I'm going to create a new route table
and I'm going to call this one "public traffic."
And again I want to make sure that we're using
the right VPC here, not the default, but our 10.2.
Wait for that to create.
So, now we have our public traffic route table.
You can see that it is not considered the main route table,
and again it doesn't have any explicit associations.
But we do want to associate this route table
with our two subnets that we created
that are meant to be public.
So I'm going to edit that and make sure that
this particular route table for public traffic
is associated with those two subnets.
And I'm going to save that.
And there we go, now you can see that
this particular route table is explicitly associated
with these two subnets.
That means that those two subnets will use whatever routes
we specify here in this route table.
So, we have our route tables attached.
Now, in order to get traffic to and from the internet,
one more thing that we need is an internet gateway.
And we don't have any for this VPC yet,
so I'm going to create one.
Again I'm going to call this one, atobs live lessons.
Sometimes it takes a second for that to show up.
There we go, so what we needed to do was undo our filter,
because this internet gateway is not attached to a VPC yet.
So, I'm going to highlight that
and I'm going to attach that internet gateway
to the appropriate VPC, in this case, the 10.2.
I'm going to go ahead and click yes, attach.
And now you can see that,
not only do we need to create the internet gateway,
but we also have to associate it or attach it to a VPC.
Now that that internet gateway is available to our VPC,
we can go back to our route tables.
I'm gonna again filter by VPC.
I'm going to choose this public traffic route table.
And you can see that we only have local traffic.
I'm going to edit that, add another route.
And in this case, I want to say all zeroes.
And you can see here, just by clicking in there,
gives me the option to choose the internet gateway
that we just created.
So this particular route says that essentially
all other traffic should be routed to the internet gateway.
So I'm going to save that.
Now there is one more thing that we need to ensure.
In order for virtual machines
within these public subnets here,
to actually communicate with the internet,
they need the internet gateway to be attached to the VPC.
They need a route table and a route entry
that actually says traffic can flow.
You can see here
that we have that route entry and that route table.
The other thing that they need is a public IP address.
Now, we can get that.
Here we can say modify auto-assign public IP.
And I'm going to check that,
so that when we launch EC2 virtual machines,
or EC2 instances as we call them, into that subnet,
we can choose for that EC twins
to automatically get a public IP.
If you don't do that,
if you end up launching an EC2 instance without a public IP,
it will not be able to communicate with the internet.
So I'm going to do the same thing here on the other subnet.
Again I'm going to modify that,
enable auto assign public IP.
And hit save.
And that way, any EC2 instances that are launched
into those subnets will receive a public IP
and their traffic will be routed
through the internet gateway to and from the internet.
And that is how we route traffic to the internet
in AWS Virtual Private Cloud.