AWS Technical Essentials – Lab 6: Configure High Availability for your Application
© 2022 Amazon Web Services, Inc. or 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. All trademarks are the property of their owners.
Note: Do not include any personal, identifying, or confidential information into the lab environment. Information entered may be visible to others.
Corrections, feedback, or other questions? Contact us at AWS Training and Certification.
Objectives
After completing this lab, you will be able to:
- Create an Application Load Balancer and a launch template
- Set up an Amazon Elastic Compute Cloud (Amazon EC2) Auto Scaling group
- Launch a template
- Test and stress a web application to validate scaling
Prerequisites
This lab requires:
- Notebook computer with Wi-Fi and Microsoft Windows, macOS, or Linux (Ubuntu, SuSE, or Red Hat)
- Administrator access (Microsoft Windows users)
- Internet browser, such as Chrome, Firefox, or Internet Explorer 9 or later
- SSH (Secure Shell) client, such as PuTTY
Note: Tablet devices cannot access the lab environment, although they can display student guides.
Duration
This lab requires 45 minutes to complete.
Start lab
- To launch the lab, at the top of the page, choos Start Lab.
This starts the process of provisioning the lab resources. An estimated amount of time to provision the lab resources is displayed. You must wait for the resources to be provisioned before continuing.
If you are prompted for a token, use the one distributed to you (or credits you have purchased).
- To open the lab, choose Open Console.
The AWS Management Console sign-in page opens in a new web browser tab.
- On the Sign in as IAM user page:
- For IAM user name, enter .
- For Password, copy and paste the Password value listed to the left of these instructions.
- Choose Sign in.
Do not change the Region unless instructed.
Common sign-in errors
Error: You must first sign out
If you see the message, You must first log out before logging into a different AWS account:
- Choose the click here link.
- Close your Amazon Web Services Sign In web browser tab and return to your initial lab page.
- Choose Open Console again.
Error: Choosing Start Lab has no effect
In some cases, certain pop-up or script blocker web browser extensions might prevent the Start Lab button from working as intended. If you experience an issue starting the lab:
- Add the lab domain name to your pop-up or script blocker's allow list or turn it off.
- Refresh the page and try again.
For this scenario, you have been tasked with setting up a load balancer and an Auto Scaling group, so your application can horizontally
scale.
In this exercise, you will create an Application Load Balancer and a
launch template. Then, you will set up an Auto Scaling group that uses
the Load Balancer and launch template you created. Finally, you will
test and stress the application and watch your application scale in real
time.
Task 1: Review Amazon Elastic Compute Cloud (Amazon EC2) Instances
Infrastructure
To support the lab, some resources are provisioned for you. The resources include an Amazon Virtual Private Cloud (Amazon VPC) with two public subnets in different Availability Zones, with a route table for each subnet, as shown.
A web application is provisioned in one of the public subnets. You will review the EC2 instance in this lab.
On the Services menu, choose EC2. Alternatively, you can type the service name in the Search box to access it.
In the left navigation pane, locate the Instances section, and choose the Instances option.
Choose your Web Application instance, which should appear in a Running state.
To show more or less information in the Details tab, drag the window divider.
Here, you can review the instance's details, including the instance type, security settings, network settings, and so forth.
Next, you will access the web application in your browser.
From the left pane, copy .
In a new browser tab, paste the URL you copied in the previous step. You should see the application, as shown.
Note: You might need to wait a few minutes before the web application becomes available.
- In the Employee Directory application, locate the Administration section in the left pane, and choose Configuration.
On this page, you can find information about where the application is running. You can identify the Availability Zone in the Configuration Settings table. You will use this value to test your load balancer later in the lab.
Next, you will create an Application Load Balancer so the application can scale horizontally when traffic increases.
Task 2: Create a Load Balancer
In this task, you will create a load balancer.
Go to the browser tab displaying the EC2 dashboard.
In the left navigation pane, locate the Load Balancing section, and choose the Load Balancers option.
Choose Create Load Balancer.
In the Load Balancer types section, below Application Load Balancer, choose the option Create.
In the Create Application Load Balancer page, configure the following fields:
Important! Do not modify any other fields.
-
In the Basic configuration section:
- Load balancer name:
-
In the Network mapping section:
- VPC, choose the
- Mappings, select both Availability Zones (AZ)
Example: If you are in US West (Oregon), you would choose both us-west-2a and us-west-2b.
- Note the subnet configured for each Availability Zone, beside the first AZ and for the second AZ.
- In the Security Groups section, choose Create a new security group link.
- Note this will open a new browser tab with the Create security group configuration options.
- In the new Create security group browser tab, configure the following fields:
- Security group name:
- Description:
Update the VPC value in the dropdown, select the Lab VPC from the dropdown.
In the Inbound rules section, choose Add Rule.
In the Type dropdown, choose HTTP.
In the Source dropdown, choose Anywhere-IPv4.
Scroll down to the bottom of the page, choose Create security group.
- Once you see the Security group has been created successfully you can close the Create security group browser tab.
Go to Load balancers browser tab and choose the Refresh button beside Security groups dropdown.
Switch back to the load balancer tab, in the Security groups, choose the security group load-balancer-sg.
Remove the default security group.
In the Listeners and routing section, under the Default action field, choose Create target group link.
- Note: This will open a new browser tab with the Create target group configuration options.
- In the new Target groups browser tab, in the Basic configuration configure the following:
- Choose Instances.
- Target group name field, enter .
In Health checks, expand Advanced health check settings.
Change the Healthy threshold to .
Change the Unhealthy threshold to .
Change the Timeout to .
Change the Interval to .
Scroll to the bottom of the page and choose Next.
In the Available instances section, choose the check box next to the instance.
Choose Include as pending below.
Choose Create target group.
Select lab-app-target-group link and choose the Targets tab.
- Once you see the target group has been created successfully you can close the Create target group browser tab.
Switch back to the load balancer tab, in the Listeners and routing section, and choose the Refresh button beside the Forward to dropdown under Default action.
In the Forward to field, select lab-app-target-group target group.
Scroll to the bottom of the page, choose Create load balancer.
Choose on View load balancer.
Select .
Note: Wait for the State to change from provisioning to active. This process can take a few minutes. You might need to choose the Refresh button at the top to see the status changes.
In the Description tab, copy the .
Paste it into a new browser tab or window.
You should see the Employee Directory application.
Note: It may take up to two minutes for target to be healthy and the url to work.
Task 3: Create a Launch Template
Now that you can access your application from a single DNS name, you can scale horizontally! To do this, you need a launch template.
In the AWS Management Console tab, on the Services menu, locate the Compute section, and choose EC2. Alternatively, you can type the service name in the Search box to access it.
In the left navigation pane, locate the Instances section, and choose Launch Templates.
Choose Create launch template.
In the Launch template name and description section, configure the following:
- Launch template name:
- Template version description:
- Auto Scaling guidance: Select the check box for 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) - required section, choose the Browse more AMIs link.
For the first Amazon Linux 2 AMI (HVM), SSD Volume Type, make sure the 64-bit(x86) option is selected, and choose Select.
In the Instance type section, choose the Instance type dropdown, and choose t3.micro.
In the Key pair (login) section, confirm that the Key pair name dropdown is set to Don't include in launch template.
Amazon EC2 uses public key cryptography to encrypt and decrypt login information. To log in to your instance, you must create a key pair, specify the name of the key pair when you launch the instance, and provide the private key when you connect to the instance.
In this lab, you will not need to connect to the instance.
In the Network settings section, choose the Security group dropdown, and choose the Web Security Group.
Expand the Advanced details section at the bottom, in the IAM instance profile, choose .
Scroll down and locate the User data.
When you launch an instance, you can pass user data to the instance. The data can be used to run common automated configuration tasks and scripts.
Your instance runs Amazon Linux, so you will provide a shell script that will run when the instance starts. This script installs the application's required dependencies. It also launches the application so you can access it in your browser.
#!/bin/bash -ex
# Update yum
yum -y update
# Add node's source repo
curl -sL https://rpm.nodesource.com/setup_15.x | bash -
#Install nodejs
yum -y install nodejs
#Install Amazon Linux extras
amazon-linux-extras install epel
#Install stress tool (for load balancing testing)
yum -y install stress
# Create a dedicated directory for the application
mkdir -p /var/app
# Get the app from Amazon S3
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/ILT-TF-100-TECESS-5/app/app.zip
# Extract it into a desired folder
unzip app.zip -d /var/app/
cd /var/app/
# Configure S3 bucket details
export PHOTOS_BUCKET=YOUR-S3-BUCKET-NAME
# Configure default AWS Region
export DEFAULT_AWS_REGION=YOUR-DEFAULT-AWS-REGION
# Enable admin tools for stress testing
export SHOW_ADMIN_TOOLS=1
# Install dependencies
npm install
# Start your app
npm start
This script performs the following tasks:
- Installs system updates
- Installs a source repository so the Node.js installer can be downloaded
- Installs Node.js
- Installs the EPEL repository that provides additional options for package installation
- Installs the stress package to stress the CPU
- Downloads the application code
- Creates a dedicated directory for the web application
- Downloads and deploys (extracts) the application into the specified directory
- Tells the application the bucket where the images are available
- Tells the application the Region where the application is running
- Installs the application dependencies
- Starts the web application
- Paste the previous snippet into the user data field, and then make the following changes:
For , replace with the value provided in this instruction's left panel.
For , replace with the value provided in this instruction's left panel.
- Choose Create launch template.
Task 4: Create an Auto Scaling Group
In this task, you will create an EC2 Auto Scaling group.
Choose View Launch templates.
In the left navigation pane, locate the Auto Scaling section, and choose Auto Scaling Groups.
Choose Create Auto Scaling group.
In the Name section, choose the Auto Scaling group name field, and type .
In the Launch template section, choose the Launch template dropdown, and choose .
Choose Next.
In the Network section, configure the following:
- In the VPC dropdown choose .
- In the Availability Zones and subnets dropdown, choose and .
Choose Next.
In the Load balancing – optional section, choose Attach to an existing load balancer.
In the Attach to an existing load balancer section, configure the following:
- Choose Choose from your load balancer target groups.
- In the Existing load balancer target groups dropdown, choose .
In the Health Checks – optional section, choose ELB.
Choose Next.
In the Group size – optional section, change the following values:
- Desired capacity to
- Minimum capacity to
- Maximum capacity to
- In the Scaling policies – optional section, configure the following:
- Choose Target tracking scaling policy.
- Change the Target value to .
- Change the Instances need to .
NOTE: The values used in this lab are for demonstration purposes. In a production environment, you would configure values based on your actual needs.
Choose Next.
In the Add notifications section, choose Add notification.
In the Notification 1 section, locate the SNS Topic option.
Choose Create a topic, and configure the following:
- Send a notification to:
- With these recipients: Your email address
Choose Next.
Choose Next again.
Scroll to the bottom of the Review screen, and choose Create Auto Scaling group.
Check for an email with the subject of AWS Notification – Subscription Confirmation, and then open it.
In the email, choose the Confirm subscription link.
A new browser tab will open with the subscription confirmation. A message should state Subscription confirmed!.
Task 5: Test the Application
Go to the browser tab where the Auto Scaling groups table is displayed.
In the left navigation pane, locate the Load Balancing section, and choose Target Groups.
Choose the link.
Choose the Targets tab.
You should see two additional instances launching (or already launched). Wait until the Status shows as healthy for both instances. Use the Refresh button to see Status changes.
In the left navigation pane, locate the Load Balancing section, and choose Load Balancers.
Choose the .
In the Description tab, copy the DNS name.
Paste the DNS name into a new browser tab or window.
You should now see the Employee Directory application.
- In the Employee Directory application, locate the Administration section in the left pane, and choose Configuration.
The Configuration Settings page will show the Availability Zone you are being routed to.
- Refresh the page a few times, and you will notice you are being routed to a different Availability Zone.
Now, you will stress the CPU of the instance to test scaling.
- In The Admin Tools section, choose the Stress Appliction For: dropdown, and choose 10 minutes. At the top, a message shows Stressing....
Note: Grab a beverage while you wait!
After approximately 10 minutes, go to the EC2 dashboard in the AWS Management Console.
In the left navigation pane, locate the Load Balancing section, and choose Target Groups.
Choose the link.
Choose the Targets tab.
Additional instances should be spun up due to the stress test. You should also receive a notification email.
Lab Complete
Congratulations! You completed the lab.
End lab
Follow these steps to close the console, end your lab, and evaluate your lab experience.
Return to the AWS Management Console.
At the upper-right corner of the page, choose awsstudent@<AccountNumber>, and then choose Sign out.
Choose End Lab.
Choose OK.
(Optional):
- Select the applicable number of stars to rate your lab experience.
- 1 star = Very dissatisfied
- 2 stars = Dissatisfied
- 3 stars = Neutral
- 4 stars = Satisfied
- 5 stars = Very satisfied
- Enter a comment.
- Choose Submit.
You can close the window if you don't want to provide feedback.
Additional Resources
- For more information about Amazon EC2 Auto Scaling, see Amazon EC2 Auto Scaling.
- For more information about AWS Training and Certification, see http://aws.amazon.com/training/.