Lab 7 Elb
Lab 7 Elb
[version_1.0]
©2019 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.
Errors or corrections? Contact us at https://support.aws.amazon.com/#/contacts/aws-training
Exercise: ELB
The exercises are designed to be completed in your AWS account, and will have an associated cost.
For this reason, in addition to the written instructions, this course includes video recordings of the
exercises. If you intend to attempt the exercises, familiarize yourself with AWS pricing, specifically
Amazon EC2 pricing, Amazon S3 pricing, and Amazon DynamoDB pricing and the AWS Free Tier.
For this scenario, you have been tasked with setting up an Elastic Load Balancer and an
AutoScaling 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 AutoScaling 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.
Lab Steps
Stage 0 - Launch an EC2 Instance
1. Search for EC2 in the search bar at the top. Choose EC2.
2. Choose Instances under Instances at the left side panel.
3. Select the employee-directory-app-lab6 instance. Which should be in the Stopped state.
4. Choose Actions. Image and templates and Launch more like this.
5. At the top, choose 3. Configure instance.
6. Next to Auto-assign Public IP, choose Enable.
7. At the top, choose 5. Add Tags. Remove lab6 at the end of the value and append lab7
instead.
Example:
employee-directory-app-lab7
13. Change the Timeout to 30 . Change the Interval to 40 . Choose Next: Register Targets.
14. Under Instances select the checkbox next to the employee-directory-app-lab7 instance
and choose Add to registered.
15. Choose Next: Review. Choose Create. Once it's successfully created choose Close.
Note: Wait for the State to change from provisioning to active. Refresh the page while you
wait.
16. Select the app-elb and copy the DNS name and paste it into a notepad. Edit the DNS name
to include an http:// in front of the URL, to look like the following:
http://app-elb-000000000.us-west-2.elb.amazonaws.com
17. Copy the DNS name with http:// and paste it into a new browser tab or window. You should
see the employee directory application.
3. Under Template version description paste in A web server for the employee directory
application .
4. Under Auto Scaling guidance check the box for Provide guidance to help me set up a
template that I can use with EC2 Auto Scaling.
5. Under AMI choose the Amazon Linux 2 AMI (HVM), SSD Volume Type.
6. Under Instance type choose the t2.micro.
https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-7-elb.html 2/5
14/10/2021, 17:21 lab-7-elb
10. Scroll down to User data and paste in the following information:
#!/bin/bash -ex
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-
GCNv2/FlaskApp.zip
unzip FlaskApp.zip
cd FlaskApp/
yum -y install python3 mysql
pip3 install -r requirements.txt
amazon-linux-extras install epel
yum -y install stress
export PHOTOS_BUCKET=${SUB_PHOTOS_BUCKET}
export AWS_DEFAULT_REGION=<INSERT REGION HERE>
export DYNAMO_MODE=on
FLASK_APP=application.py /usr/local/bin/flask run --host=0.0.0.0 --port=80
Example:
Note: US West (Oregon)
export AWS_DEFAULT_REGION=us-west-2
export PHOTOS_BUCKET=<INSERT_BUCKET_NAME>
Example:
export PHOTOS_BUCKET=employee-photo-bucket-al-007
https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-7-elb.html 3/5
14/10/2021, 17:21 lab-7-elb
http://app-elb-0000000000.us-west-2.elb.amazonaws.com/info
You should be presented with Instance Info which will show you which instance_id and
availability_zone you are being routed to. Refresh the page a few times and you will notice
you are being routed to a different instance_id and availability_zone.
4. Now, you will need to stress the CPU of the instance in order to test Auto Scaling.
5. Next to Stress cpu: choose 10 min. At the top you will notice it now says Stressing CPU.
Note: Go grab a beverage as you wait :)
6. After the 10 minutes are up, go back in the EC2 Console. Under Load Balancing on the left
side panel, choose Target Groups. Choose the app-target-group . Choose the Targets tab.
7. You should see additional instances being spun up due to the stress test. You should also see
a notification email as well.
6. In the DynamoDB console, on the left side panel, click on Tables. Then, click the circle next to
the Employees table. Choose Delete Table. Type in the word delete and select Delete.
7. In the S3 console, find the employee-photo-bucket. Select the circle next to the bucket you
created. Then, choose Empty. Type in permanently delete in the text field. Select Empty.
Choose Exit. Now, choose Delete. Type in the name of your bucket in the text field and
choose Delete bucket.
8. In the VPC console, on the left side panel, click on Route Tables. Select the checkbox next to
app-route-table-public and click on the Subnet Associations tab. Select Edit subnet
associations. Deselect the boxes next to both Public Subnets and click save. Select Actions
and then Delete. Then, choose Delete Route Table again. Follow the same steps for app-
route-table-private.
9. In the VPC console, on the left side panel, click on Internet Gateways. Select the app-igw and
choose Detach from VPC and choose Detach Internet Gateway. Then, click Actions and
select Delete Internet Gateway. Type in delete in the text field and select Delete Internet
Gateway.
10. In the VPC console, on the left side panel, select Subnets. Select the boxes next to Public
Subnet 1, Public Subnet 2, Private Subnet 1, and Private Subnet 2. Select Actions and then
delete subnet. Type delete in the text field. Then, choose Delete.
11. In the VPC console, on the left side panel, select Your VPCs. Select the checkbox next to app-
vpc. Select Actions and then Delete VPC. Type delete in the text field and then choose
Delete.
Lab Complete
Congratulations! You have completed the lab.
For feedback, suggestions, or corrections, please contact us at:https://support.aws.amazon.co
m/#/contacts/aws-training
https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/lab-7-elb.html 5/5