Module 9 - Guided Lab - Creating A Highly Available Environment
Module 9 - Guided Lab - Creating A Highly Available Environment
Environment
Lab overview and objectives
Critical business systems should be deployed as highly available applications—that is, applications remain operational even when
some components fail. To achieve high availability in Amazon Web Services (AWS), we recommend that you run services across
multiple Availability Zones.
Many AWS services are inherently highly available, such as load balancers. Many AWS services can also be configured for high
availability, such as deploying Amazon Elastic Compute Cloud (Amazon EC2) instances in multiple Availability Zones.
In this lab, you will start with an application that runs on a single EC2 instance. You will then make the application highly available.
After completing this lab, you should be able to:
Inspect a provided virtual private cloud (VPC)
Create an Application Load Balancer
Create an Auto Scaling group
Test the application for high availability
At the end of this lab, your architecture will look like the following example:
Duration
The lab requires approximately 40 minutes to complete.
2. Wait until the Start Lab panel displays the message Lab status: ready, then close the panel by choosing the X.
4. Arrange the AWS Management Console tab so that it displays alongside these instructions. Ideally, you will have both
browser tabs open at the same time so that you can follow the lab steps more easily.
Do not change the Region unless specifically instructed to do so.
A VPC
Public and private subnets in two Availability Zones
An internet gateway (not shown) that is associated with the public subnets
A Network Address Translation (NAT) gateway in one of the public subnets
An Amazon Relational Database Service (Amazon RDS) instance in one of the private subnets
In this task, you will review the configuration of the VPC that was created for this lab.
6. In the left navigation pane, under Filter by VPC, choose the Select a VPC box and select Lab VPC.
This setting will limit the console to only show resources that are associated with the Lab VPC.
10. In the lower half of the page, choose the Route table tab.
This tab includes details about the routing for this subnet:
The first entry specifies that traffic destined within the Classless Inter-Domain Routing (CIDR) range for the VPC
(10.0.0.0/16) will be routed within the VPC (local).
The second entry specifies that any traffic destined for the internet (0.0.0.0/0) is routed to the internet gateway (igw-) that
exists in Lab VPC. This setting makes the subnet a public subnet.
15. In the lower half of the page, choose the Inbound rules tab.
The rule defined in this security group permits inbound MySQL or Aurora traffic (port 3306) from anywhere in the VPC
(10.0.0.0/16). You will later modify this setting so it only accepts traffic from the application servers.
18. In the left navigation pane, choose Load Balancers (you might need to scroll down to find it).
22. Scroll down to the Network mapping section, then for VPC, select Lab VPC.
Important: Be sure to choose Lab VPC. It is likely not the default selection.
You will now specify which subnets the load balancer should use. It will be a public load balancer, so you will select both public
subnets.
23. Under Mappings, choose the first Availability Zone, then choose the Public Subnet that displays.
24. Choose the second Availability Zone, then choose the Public Subnet that displays.
You should now have selected two subnets: Public Subnet 1 and Public Subnet 2. (If not, go back and try the configuration
again.)
25. In the Security groups section, select the Create a new security group hyperlink. This opens a new browser tab. Configure
the new security group settings:
Security group name: Inventory-LB
VPC: Remove the default VPC by choosing the X to the right of it. Then select Lab VPC.
26. Under Inbound rules, choose Add rule and configure as described:
Type: HTTP
Source: Anywhere-IPv4
27. Still under Inbound rules, choose Add rule again and configure:
Type: HTTPS
Source: Anywhere-IPv4
30. In the Listeners and routing section, choose Create target group.
A new browser tab will open.
Analysis: Target groups define where to send traffic that comes into the load balancer. The Application Load Balancer can
send traffic to multiple target groups based upon the URL of the incoming request, such as having requests from mobile apps
going to a different set of servers. Your web application will use only one target group.
Interval: 10 (seconds)
The configurations you have chosen will result in the health check being performed every 10 seconds, and if the instance
responds correctly twice in a row, it will be considered healthy.
Choose Next. The Register targets screen appears.
Note: Targets are the individual instances that will respond to requests from the load balancer.
You do not have any web application instances yet, so you can skip this step.
Review the settings and choose Create target group.
32. Return to the browser tab where you already started defining the load balancer.
33. In the Listeners and routing section, choose the refresh icon.
34. For the Listener HTTP:80 row, set the Default action to forward to the Inventory-App target group you just created.
35. Scroll to the bottom of the page, and choose Create load balancer.
The load balancer is successfully created.
Choose View load balancer.
36. In the AWS Management Console, on the Services menu, choose EC2.
38. Wait until the Status check for Web Server 1 displays 2/2 checks passed. Choose refresh to update.
You will now create an AMI based upon this instance.
40. In the Actions menu, choose Image and templates > Create image, then configure:
Image name: Web Server AMI
Under Auto Scaling guidance, select Provide guidance to help me set up a template that I can use with EC2 Auto Scaling
In the Application and OS Images (Amazon Machine Image) area, choose My AMIs.
Amazon Machine Image (AMI): choose Web Server AMI
Instance type: choose t2.micro
Key pair name: choose vockey
Firewall (security groups): choose Select existing security group
Security groups: choose Inventory-App
Scroll down to the Advanced details area and expand it.
IAM instance profile: choose Inventory-App-Role
Scroll down to the Detailed CloudWatch monitoring setting. Select Enable
Note: This will allow Auto Scaling to react quickly to changing utilization.
Under User data, paste in the script below:
#!/bin/bash
# Install Apache Web Server and PHP
yum install -y httpd mysql
amazon-linux-extras install -y php7.2
# Download Lab files
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/ILT-TF-200-ACACAD-20-EN/mod9-
guided/scripts/inventory-app.zip
unzip inventory-app.zip -d /var/www/html/
# Download and install the AWS SDK for PHP
wget https://github.com/aws/aws-sdk-php/releases/download/3.62.3/aws.zip
unzip aws -d /var/www/html
# Turn on web server
chkconfig httpd on
service httpd start
46. From the Actions menu, choose Create Auto Scaling group
50. Configure the details in Step 4 (Configure group size and scaling policies - optional):
Under Group size, configure:
Desired capacity: 2
Minimum capacity: 2
Maximum capacity: 2
This will allow Auto Scaling to automatically add/remove instances, always keeping between 2 and 6 instances
running.
Under Scaling policies, choose None
For this lab, you will maintain two instances at all times to ensure high availability. If the application is expected to receive
varying loads of traffic, you can also create scaling policies that define when to launch or terminate instances. However,
you do not need to create scaling policies for the Inventory application in this lab.
Choose Next
51. Configure the details in Step 5 (Add notifications - optional):
You do not need to configure any of these settings.
Choose Next
Value: Inventory-App
These settings will tag the Auto Scaling group with a Name, which will also appear on the EC2 instances that are launched
by the Auto Scaling group. You can use tags to identify which Amazon EC2 instances are associated with which
application. You could also add tags such as Cost Center to assign application costs in the billing files.
Choose Next
56. In the lower half of the page, choose the Inbound rules tab.
The security group is currently empty. You will now add a rule to accept incoming HTTP traffic from the load balancer. You do not
need to configure HTTPS traffic because the load balancer was configured to forward HTTPS requests via HTTP. This practice
offloads security to the load balancer, reducing the amount of work that is required by the individual application servers.
58. On the Edit inbound rules page, choose Add rule and configure these settings:
Type: HTTP
Source:
Choose the search box to the right of Custom
Delete the current contents
Enter sg
59. In the Security groups list, choose Inventory-DB (and make sure that no other security groups are selected).
The existing rule permits traffic on port 3306 (used by MySQL) from any IP address within the VPC. This is a good rule, but
security can be restricted further.
60. In the Inbound rules tab, choose Edit inbound rules and configure these settings:
Delete the existing rule.
Choose Add rule.
For Type, choose MYSQL/Aurora
Choose the search box to the right of Custom
Enter sg
63. In the lower half of the page, choose the Targets tab.
This tab should show two registered targets. The Health status column shows the results of the load balancer health check
that is performed against the instances.
64. In the Registered targets area, occasionally choose the refresh icon until the Status for both instances appears as healthy.
If the status does not eventually change to healthy, ask your educator for help with diagnosing the configuration.
You will test the application by connecting to the load balancer, which will then send your request to one of the EC2
instances. You will first need to retrieve the Domain Name System (DNS) name of the load balancer.
65. In the left navigation pane, choose Load Balancers and then choose Inventory-LB.
66. In the Details tab in the lower half of the window, copy the DNS name to your clipboard.
It should be similar to: inventory-LB-xxxx.elb.amazonaws.com
67. Open a new web browser tab, paste the DNS name from your clipboard and press ENTER.
The load balancer forwarded your request to one of the EC2 instances. The instance ID and Availability Zone are shown at the
bottom of the webpage.
68. Reload the page in your web browser. You should notice that the instance ID and Availability Zone sometimes toggles
between the two instances.
When this web application displays, the flow of data over the network is:
You sent the request to the load balancer, which resides in the public subnets that are connected to the internet.
The load balancer chose one of the EC2 instances that reside in the private subnets and forwarded the request to it.
The EC2 instance then returned the webpage content to the load balancer, which returned it to your web browser.
69. Return to the EC2 console tab in your web browser (but do not close the web application tab—you will return to it soon).
71. Select one of the Inventory-App instances (it does not matter which one you select).
74. Return to the web application tab in your web browser and reload the page several times.
You should notice that the Availability Zone that is shown at the bottom of the page stays the same. Though an instance failed,
your application remains available.
After a few minutes, Amazon EC2 Auto Scaling will also notice the instance failure. It was configured to keep two instances
running, so Amazon EC2 Auto Scaling will automatically launch a replacement instance.
75. Return to the EC2 console tab where you have the instances list displayed. In the top-right area, choose the refresh icon
every 30 seconds or so until a new EC2 instance appears.
After a few minutes, the health check for the new instance should become healthy. The load balancer will resume sending
traffic between the two Availability Zones. You can reload your web application tab to see this happen.
This task demonstrates that your application is now highly available.
78. Choose the link for the name of the inventory-db instance.
Feel free to explore the information about the database.
80. Scroll down to the Availability & durability section. For Multi-AZ deployment, select Create a standby instance.
Analysis: You only need to reconfigure this one setting to convert the database to run across multiple data centers (Availability
Zones).
This option does not mean that the database is distributed across multiple instances. Instead, one instance is the primary
instance, which handles all requests. Another instance will be launched as the standby instance, which takes over if the
primary instance fails. Your application continues to use the same DNS name for the database. However, the connections will
automatically redirect to the currently active database server.
You can scale an EC2 instance by changing attributes, and you can also scale an RDS database this way. You will now scale up
the database.
81. Scroll back up and for DB instance class, select db.t3.small.
This action doubles the size of the instance.
This action doubles the amount of space that is allocated to the database.
Feel free to explore the other options on the page, but do not change any other settings.
The current architecture has only one NAT gateway in Public Subnet 1. Thus, if Availability Zone 1 fails, the application servers will
not be able to communicate with the internet.
In this optional task, you will make the NAT gateway highly available by launching another NAT gateway in the other Availability
Zone. The resulting architecture will be highly available:
Target: Select NAT Gateway, then select the nat- entry that is not the entry for _NATGateway1
Tip: To discover which nat- entry is NOT the one to select, choose the Details button above these instructions and then
select Show. the name of NATGateway1 is displayed. Return to the VPC console and select the Target that is NOT
NATGateway1.
Choose Save changes
98. If the results don't display after a couple of minutes, return to the top of these instructions and choose Grades
Tip: You can submit your work multiple times. After you change your work, choose Submit again. Your last submission is
what will be recorded for this lab.
99. To find detailed feedback on your work, choose Details followed by View Submission Report.
Lab complete
Congratulations! You have completed the lab.
100. Choose End Lab at the top of this page, and then select Yes to confirm that you want to end the lab.
A panel indicates that DELETE has been initiated... You may close this message box now.
101. Select the X in the top right corner to close the panel.
©2023 Amazon Web Services, Inc. and its affiliates. All rights reserved. This work may not be reproduced or redistributed, in whole or in
part, without prior written permission from Amazon Web Services, Inc. Commercial copying, lending, or selling is prohibited.