Exercise 7 - ELB
Exercise 7 - ELB
1]
Note
The exercises in this course will have an associated charge in your AWS account. In
this exercise, you create or use the following resources:
AWS Identity and Access Management (IAM) policy and user (policies and users
are AWS account features, offered at no additional charge)
Amazon Elastic Compute Cloud (Amazon EC2) instance
Elastic Load Balancing (ELB) load balancer
AWS Auto Scaling
Amazon Simple Notification Service (Amazon SNS) topic
Familiarize yourself with Amazon EC2 pricing, Elastic Load Balancing pricing, AWS
Auto Scaling pricing, Amazon SNS pricing, and the AWS Free Tier.
In this exercise, you first launch another EC2 instance. You then create an Application Load
Balancer and a launch template. Next, you set up an Auto Scaling group that uses the load
balancer and launch template that you created. Finally, you test and stress the application,
and watch your application scale in real time.
5. Choose Actions and then choose Image and templates, Launch more like this.
Example:
employee-directory-app-exercise7
7. For Key pair name, select app-key-pair.
11. Wait for the Instance state to change to Running and the Status check to change to
2/2 checks passed.
13. On the Details tab, copy the Public IPv4 address and paste it into a new browser
window.
14. In a new browser window, paste the IP address that you copied. Make sure to remove
the ‘S’ after HTTP so you are using only HTTP instead.
6. In the Security groups section, remove the default security group (by choosing the X)
and choose Create new security group.
10. For Security groups, add the new load-balancer-sg group. Note: To see the new
security group, you might need to refresh the Security groups list.
16. Close the target groups window or return to the Load balancers window.
17. Under Listeners and routing, refresh the available listener and choose app-target-
group.
20. Make sure that app-alb is selected and wait for the load balancer State to become
Active.
21. On the Description tab, copy DNS name and paste it into a text editor of your choice.
22. In the text editor, at the beginning of the URL, add http:// .
Example:
http://app-elb-123456789012.us-west-2.elb.amazonaws.com
23. Copy the DNS name (with http:// added) and paste it into a new browser window.
#!/bin/bash -ex
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/DEV-AWS-MO-GCNv2/FlaskApp
unzip FlaskApp.zip
cd FlaskApp/
yum -y install python3-pip
pip install -r requirements.txt
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
7. In the user data code, replace the PHOTOS_BUCKET placeholder value with the name of
your bucket.
Example:
export PHOTOS_BUCKET=employee-photo-bucket-al-907
8. Replace the AWS_DEFAULT_REGION placeholder value with your Region (the Region is
listed at the top right, next to your user name).
Example:
export AWS_DEFAULT_REGION=us-west-2
4. Choose Next.
6. Choose Next.
8. Choose Next.
9. For Configure group size and scaling policies, use these settings:
Desired capacity: 2
Minimum capacity: 2
Maximum capacity: 4
Scaling policies: Target tracking scaling policy
Target value: 60
Instances need: 300
11. For Add notifications, choose Add notification and configure these settings:
SNS Topic: Create a topic
Send a notification to: app-sns-topic
With these recipients: Enter your email address
5. In the navigation pane, choose Load Balancers and make sure that app-alb is
selected.
6. Again, copy the DNS name and paste it into a text editor of your choice.
7. In the text editor, at the beginning of the URL, add http:// and copy the modified
URL.
Example:
http://app-elb-123456789012.us-west-2.elb.amazonaws.com
Example:
http://app-alb-123456789012.us-west-2.elb.amazonaws.com/info
You should see an Instance Info page, which shows which instance_id and
availability_zone you are being routed to.
10. Refresh the page a few times. Each time, note that the values for instance_id or
availability_zone can be different from the previous ones.
Now, you need to test auto scaling by stressing the CPU of the instance.
The top of the browser window should show a message that says Stressing CPU.
12. Wait for 10 minutes and after the 10 minutes are over, return to the Amazon EC2
console window.
13. In the navigation pane, under Load Balancing, choose Target Groups.
You should see additional instances were launched because of the stress test. You should
also see a notification email.
© 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. Corrections, feedback, or
other questions? Contact us at https://support.aws.amazon.com/#/contacts/aws-training. All
trademarks are the property of their owners.