Practice in your account · 30 min
A three-tier VPC in two Availability Zones
In this lab you will create a VPC with public, application and data subnets in two Availability Zones, and you will check in the console what makes each one public, private or isolated.
In this lab you will build a VPC, which is a private network of your own inside AWS where you put your servers and decide who can talk to them. That network is divided into subnets, which are smaller parts of the network with their own rules. This lab's VPC has three tiers of subnets (public, application and data), repeated in two Availability Zones. For example, an online store would put its front page in the public tier, the program that processes orders in the application tier and its customer database in the data tier.
You will create it with a CloudFormation template and then check in the console the three pieces that decide who talks to whom: route tables, network ACLs and security groups. These topics belong to domain 1 of the exam, in the part about network security, and to domain 2, because of the use of two zones. For example, if one zone fails, the store keeps taking orders with the subnets in the other zone.

The full version of this architecture uses three zones, a load balancer that distributes visits across several servers, NAT gateways and databases. The template builds only the network for zones A and B and leaves out everything that charges, so it doesn't create a load balancer, NAT or instances. In that network, each tier has its own route table, and the public and data subnets also have their own network ACL.
The network uses the same CIDR blocks as the full version. A CIDR block is the range of addresses assigned to a network or a subnet, where each IP address is for one server. It is written like 10.0.0.0/16, and the number after the slash says how big the range is: the smaller that number, the more addresses fit. For example, a /24 subnet has 256 addresses, while a /20 has many more, so the application tier, which is a /20, leaves room for many more order servers.
Before you start
First do the budget lab, so that any charge reaches you as an alert. If you have a full account, choose the Region in the top right and use the same one when you delete the stack, because a stack only shows up in the Region where you created it.
The lab's VPC uses the 10.0.0.0/16 block, which doesn't clash with the default VPC's (172.31.0.0/16). The default VPC is a network AWS creates on its own in each Region of a full account, and two blocks not clashing means the two networks don't use the same addresses. For example, if the store's network and the default one used the same addresses and someday you connected them, a message wouldn't know which of the two networks it has to reach.
If your account is a new experience account, your project is in us-east-2 and the console has no Region selector, so the VPC is created there.
Create the VPC with the template
CloudFormation creates a template's resources all together, as a stack, and that stack is updated and deleted as a whole. For example, when you delete this lab's stack, the VPC, its subnets and its tables will be deleted together, without you having to look for each one. When you create it, the template lets you choose parameters, which are options such as ModoNat, and with the values in these steps it creates nothing that charges.
- Open the CloudFormation console and choose Create stack, With new resources (standard).
- Choose Upload a template file, upload
[lab03-vpc-tres-capas.yaml](/roadmaps/plantillas/lab03-vpc-tres-capas.yaml)and choose Next. - Name the stack
cloudpath-saa-lab03-vpc. LeaveModoNatset toningunoandConFlowLogsset tono. - Choose Next twice and then Submit. In a couple of minutes the stack reaches
CREATE_COMPLETE.
CREATE_COMPLETE is the status CloudFormation shows when it has finished creating all the stack's resources without errors. For example, when this lab's stack reaches that status, the VPC and its six subnets already exist and you can check them in the Amazon VPC console.
Check the subnets and route tables
A route table is the list of paths that traffic leaving a subnet follows: each route says which addresses the traffic is going to and where it goes out. The 0.0.0.0/0 route means any address, that is, the internet, and the local route is the one that connects the subnets of the same VPC to each other. A subnet is public when its table has a route to the internet gateway, which is the VPC's door to the internet. For example, the store's front page goes in a public subnet because its customers come from the internet, while the database goes in a subnet without that route.
Every resource the template creates carries the stack name as a prefix, so the VPC is called cloudpath-saa-lab03-vpc-vpc and the rt-publica table shows up in the console as cloudpath-saa-lab03-vpc-rt-publica.
- Open the Amazon VPC console, go to Subnets and filter by the
cloudpath-saa-lab03-vpc-vpcVPC. There are six subnets: two public /24 subnets, two application /20 subnets and two data /24 subnets. In the available IPv4 addresses column, a /24 shows 251 and not 256, because AWS reserves five addresses in each subnet. - Go to Route tables and compare these tables:
-
rt-publica, which has0.0.0.0/0to the internet gateway (igw-...) and is associated with the two public subnets. That route is what makes a subnet public. -rt-app-aandrt-app-b, which only have the local route. Since there is no NAT, the application tier can't reach the internet yet. -rt-datos, which only has the local route, so the data tier is isolated.
These tables decide where each subnet's traffic can go out. The application tier is private: its servers talk to the other subnets in the VPC, but they can't reach the internet until you add a NAT gateway, which is a service that lets a private subnet go out to the internet without letting anyone in from outside. The data tier, on the other hand, is isolated, and an instance in datos-a can't reach the internet even if it has a public IP, because its route table has no path to the internet gateway and a public IP is useless without that route. For example, if someone at the store launches a server in datos-a with a public IP by mistake, that server still has no way out to the internet.
Does it reach the internet?
You launch an instance in the datos-a subnet and assign it a public IP. Can it reach the internet?
Check the network ACLs and security groups
Network ACLs and security groups are the other two pieces that decide who talks to whom, and both work with rules by port number. A network ACL is a list of rules that applies to a whole subnet and says which traffic can enter and leave it. A security group does something similar, but it applies to each server instead of to the subnet. For example, at the store, the data network ACL checks all the traffic that reaches the data subnets, and the database's security group checks only the traffic that reaches the database.
The template's network ACLs are associated with the public subnets and the data subnets. These ACLs are stateless, which means they don't remember connections and check what comes in and what goes out separately. When an application server asks the database something, the response comes back to an ephemeral port, which is a high number the server asking picks on the spot to receive that response. For example, if acl-datos let 5432 in but didn't let traffic out to the ephemeral ports, the order server's question would reach the database and the response would never come back.
- Go to Network ACLs.
acl-publicalets in 443, the ephemeral ports 1024-65535 and everything that comes from 10.0.0.0/16.acl-datosonly lets in 5432 from the two application subnets and lets traffic out to their ephemeral ports. ACLs are stateless, so the response of each connection needs its own rule. - Go to Security groups and follow the chain between
sg-alb,sg-appandsg-db.

The template's security groups are chained between the tiers. In a chain of security groups, each group accepts traffic from another group instead of from an IP range. In your stack, sg-alb accepts 443 from 0.0.0.0/0, sg-app accepts 8080 only from sg-alb and sg-db accepts 5432 only from sg-app. Thanks to this chain, if tomorrow you add instances to the application tier, the database already accepts them without you touching any rule. For example, if the store adds order servers for a sale season and gives them sg-app, the database accepts them from the first moment, and a server without that group can't reach the database even if it is in the same VPC.
True or false?
0 of 3In a network ACL, the response of an allowed connection goes out without needing another rule.
sg-db accepts port 5432 from any address in the VPC.
If you add instances with sg-app to the application tier, the database accepts them without changing any rule.
Internet access with a NAT gateway
This part is optional, because everything it adds charges by the hour while it exists: the NAT gateway, its public IP and the test instance. A NAT gateway lets the servers in a private subnet go out to the internet without anyone on the internet being able to start a connection to them. For example, the store's order server could download an update through the NAT gateway, and still no visitor could connect directly to it.
The ModoNat parameter adds NAT gateways and a test instance without a public IP, which you access with Session Manager. That instance needs permissions to use Session Manager, and that is why the update asks you to confirm that the template creates IAM resources, IAM being the AWS service where those permissions are defined.
To turn it on, in Stack actions choose Update, use the current template, change ModoNat to zonal and check the IAM resources box under Capabilities. When the update finishes, check rt-app-a again, which now has 0.0.0.0/0 to nat-.... When you're done, do another update to set ModoNat back to ninguno.
How to know you're done
To check the network from CloudShell, run these commands:
VPC=$(aws cloudformation describe-stacks --stack-name cloudpath-saa-lab03-vpc \
--query "Stacks[0].Outputs[?OutputKey=='VpcId'].OutputValue" --output text)
aws ec2 describe-subnets --filters "Name=vpc-id,Values=$VPC" \
--query "Subnets[].[Tags[?Key=='Name']|[0].Value,CidrBlock,AvailabilityZone,AvailableIpAddressCount]" \
--output table
aws ec2 describe-route-tables --filters "Name=vpc-id,Values=$VPC" \
--query "RouteTables[].[Tags[?Key=='Name']|[0].Value,length(Routes)]" --output table
The first command saves your network's identifier in the VPC variable, and the other two request the list of subnets and route tables of that network, as a table. The result has to show six subnets spread across two zones and the public table with two routes: the local one and the internet gateway one. For example, next to rt-datos there has to be a single route, the local one, because that table has no path to the internet.
Delete what you created
To delete the network, in CloudFormation select cloudpath-saa-lab03-vpc and choose Delete. With ModoNat set to ninguno this stack doesn't charge, so you can keep it if you plan to use the network later. If you updated it with NAT, delete it or set it back to ninguno the same day.
Next
- Create a VPC: https://docs.aws.amazon.com/vpc/latest/userguide/create-vpc.html. With the VPC and more wizard you can build a similar VPC by hand; leave NAT gateways set to None so it doesn't charge.
- cloud path practice exams: /examenes?lang=en