0% found this document useful (0 votes)
81 views14 pages

Module 4 Challenge

The document describes steps to analyze, connect to, and configure an EC2 instance running a LAMP stack to host a café website. It involves: 1) Connecting to the EC2 instance using AWS Cloud9 IDE and observing the running instance and Cloud9 environment. 2) Analyzing the LAMP stack, downloading application files, and configuring the database and Systems Manager parameters. 3) Testing the application by placing test orders and resolving issues loading the full website.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views14 pages

Module 4 Challenge

The document describes steps to analyze, connect to, and configure an EC2 instance running a LAMP stack to host a café website. It involves: 1) Connecting to the EC2 instance using AWS Cloud9 IDE and observing the running instance and Cloud9 environment. 2) Analyzing the LAMP stack, downloading application files, and configuring the database and Systems Manager parameters. 3) Testing the application by placing test orders and resolving issues loading the full website.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Task 1: Analyzing the existing EC2 instance

In this task, you will note details about an existing EC2 instance that was created
for you in the AWS account.

5. In the search box next to Services, search for and select EC2, to go to the
EC2 console. Then choose Instances.

Notice the running instance named aws-cloud9-CafeWebServer-.... This EC2


instance was created when you started the lab.

Task 2: Connecting to the IDE on the EC2 instance


AWS Cloud9 is service that can run on an EC2 instance. It provides an integrated
development environment (IDE) that includes features such as a code editor,
debugger, and terminal.

By using the AWS Cloud9 environment, you don't need to download a key pair
and connect to the EC2 instance by using PuTTY or similar Secure Shell (SSH)
software. By using AWS Cloud9, you also don't need to use command line text-
editing tools (like vi or nano) to edit files on the Linux instance.

8. In the search box next to Services, search for and select Cloud9, to go to
the AWS Cloud9 console.

In the Environments page, notice the CafeWebServer environment. It


indicates that it is of type EC2 instance.

9. Choose Open.

You are now connected to the AWS Cloud9 IDE that is running on the EC2
instance that you observed earlier.

The IDE includes:

o A Bash terminal in the bottom-right panel.

o A file browser in the left panel that shows files in the


/home/ec2-user/environment directory on the instance.
o A file editor in the upper-right panel. If you double-click a file in the
file browser—such as the README.md file—it will display in the
editor.

Task 3: Analyzing the LAMP stack environment


and confirming that the web server is accessible
Recall that the objective of this challenge lab is configure an EC2 instance to host
the new dynamic website for the café. In this task, you will analyze what is
already installed.

10.Observe the OS version.

In the AWS Cloud9 bash terminal, run this command:

cat /proc/version

Notice how the output indicates it is an Amazon Linux instance, roughly


analogous to Red Hat 7.

11.Observe the web server, database, and PHP details and server state.

In the terminal, run these commands:

sudo httpd -v
service httpd status
mysql --version
service mysqld status

php --version

The output should show the versions of the web server and the database,
and also show that they are not currently running.

12.Start the web server and the database, and also set them to start
automatically after any future EC2 instance restart.

In the terminal, run these commands:

sudo chkconfig httpd on


sudo service httpd start
sudo service httpd status

sudo chkconfig mysqld on


sudo service mysqld start
sudo service mysqld status

13.Configure the EC2 instance so that you can use the AWS Cloud9 editor to
edit web server files.

Notice that the AWS Cloud9 file browser currently does not display the
Apache web server default web directory.

In the terminal, run these two commands:

ln -s /var/www/ /home/ec2-user/environment
sudo chown ec2-user:ec2-user /var/www/html
The first command you ran created a symlink from the default AWS
Cloud9 editor workspace to the /var/www directory that contains your web
server files.

The second command changed ownership of the html subdirectory so


that the ec2-user (which you are logged in as) can edit and create new files
in it.

14.Creating a simple test webpage.


o In the file browser, expand the CafeWebServer > www directory,
and highlight the html directory.
o Choose File > New File.
o In the text editor tab, paste the following line:

<html>Hello from the café web server!</html>

o Choose File > Save, and save the file in the html directory as
index.html.

15.Make the website accessible from the internet.

In this step, you will need to verify and update the configurations that
make the webpages (which are hosted on the web server) accessible from
the internet.

Task 4: Installing the café application


16.Download and extract the web server application files.

In the Bash terminal, run these commands:


cd ~/environment
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/ILT-TF-200-ACACAD-20-EN/mod4-
challenge/setup.tar.gz
tar -zxvf setup.tar.gz
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/ILT-TF-200-ACACAD-20-EN/mod4-
challenge/db.tar.gz
tar -zxvf db.tar.gz
wget https://aws-tc-largeobjects.s3-us-west-2.amazonaws.com/ILT-TF-200-ACACAD-20-EN/mod4-
challenge/cafe.tar.gz
tar -zxvf cafe.tar.gz

Notice how the file browser now shows the three .tar.gz files that you
downloaded.

You also extracted these archive files, which created the cafe , db , and setup
directories in your work environment.

17.Copy the café files over to the web server document root.

In the Bash terminal, run this command:

mv cafe /var/www/html/

18.Observe how the application is designed to work.

o Open the html/cafe/index.php source code in the AWS Cloud9 editor by


double-clicking it.

o Notice that this file has HTML code in it, but it also contains sections
that are enclosed in elements. These elements make calls to other
systems and resources.
o For example, on line 18, you see that the PHP code references a file
named getAppParameters.php.

o Open the getAppParameters.php file in the code editor.

o Notice on line 3 of this file that the AWSSDK is invoked.

o Also, on lines 10–33, the web application creates a client that


connects to the ssm service, which is AWS Systems Manager. The
application then retrieves seven parameters from Systems
Manager. Those parameters have not been created in AWS Systems
Manager yet, but you will do that next.

19.In the AWS Systems Manager Parameter Store, configure the application
parameters.

In the Bash terminal, run these commands:

cd setup
./set-app-parameters.sh

The shell script that you just ran issued AWS Command Line Interface
(AWS CLI) commands. These commands added the parameters that the
application will use to the Parameter Store.

20.In the AWS Management Console, from the Services menu, choose
Systems Manager.

21.From the panel on the left, choose Parameter Store.

Notice how there are now seven parameters stored here.


The café application's PHP code references these values (for example, so
that it can retrieve the connection information for the MySQL database).

Choose the /cafe/dbPassword parameter, and copy the Value to your


clipboard. You will use this value in a moment.

22.Configure the MySQL database to support the café application.

Back in the AWS Cloud9 bash terminal, run the following commands:

cd ../db/
./set-root-password.sh
./create-db.sh

23.Observe the database tables that were created.

In the Bash terminal, run this command to connect the terminal-based


MySQL client to the database:

mysql -u root -p

When you are prompted for the database password, paste the
dbPassword parameter value that you copied.

You should now see a mysql> prompt, which indicates that you are now
connected to the MySQL database that runs on this EC2 instance.
To observe the contents of the database (specifically, the tables that support the
café web application), enter the following commands:

show databases;
use cafe_db;
show tables;
select * from product;
exit;

24.Update the timezone configuration in PHP.

In the Bash terminal, run the following commands:

sudo sed -i "2i date.timezone = \"America/New_York\" " /etc/php.ini


sudo service httpd restart

The first command that you ran configured the time zone in the PHP
software.

The second command that you ran restarted the web server so that the
web server notices the configuration update.

25.Test whether the café website is working and can be accessed from the
internet.

In a new browser tab, try to load the application at http://<public-ip>/cafe


where <public-ip> is the IPv4 public IP address of the EC2 instance.

You will see that only the title banner of the website loads. The rest of the
webpage is not loading correctly.
26.Resolve an issue with the website.

In this step, you will need to figure out how to make the café website
function correctly.

Here's a list of what does work:

o The test page at http://<public-ip>/ loads, so you know that the web
server works, and is accessible from the internet

o You also know that the MySQL database is running, and contains
tables and data to support the application

Task 5: Testing the web application


27.Test by placing an order.

o In the browser tab where you have the http://<public-ip>/cafe page


open, choose Menu.

o Submit an order for at least one of the menu items displayed.

 Note: you may need to scroll down to find the Submit Order
button.

o Return to the menu page and place another order, then go to the
Order History page to see the order details for all the orders that
you placed.

Task 6: Creating an AMI and launching another


EC2 instance
Because the café website already runs well on an existing EC2 instance, Sofía
decides to duplicate it by creating an AMI from it. She will then launch a new
instance from the new AMI.

You will continue to take on the role of Sofía for this task. Before you create an
AMI out of this instance, you should create a new key pair, which might be
important to have later in this lab.
28.Set a static internal hostname and create a new key pair on the EC2
instance.

In the bash terminal, run the following commands:

sudo hostname cafeserver


ssh-keygen -t rsa -f ~/.ssh/id_rsa

For the two times that you are prompted for a passphrase, press the
ENTER key.

To make the new key available to the SSH utilities, in the Bash terminal,
run the following command:

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

29.In the AWS Management Console, browse to the EC2 service area and
select the instance.

30.Choose Actions > Images and templates > Create Image.

Tip: Leave the Create Image dialog open in the browser tab while you
answer some questions about AMIs.

33.Back in the AWS Management Console, in the Create Image screen,


create the new AMI:
o Image name: CafeServer
o Choose Create Image
34.From the navigation menu, choose AMIs and wait until the image status
becomes Available. The process typically takes about 2 minutes. You may
need to expand Images to find AMIs.

35.Create an AMI in another AWS Region

In this step, your objective is to create a new EC2 instance from the AMI
that you just captured. However, you must create the new instance in the
Oregon (us-west-2) AWS Region.

Tip #1 (click to expand)Tip #2 (click to expand)Tip #3 (click to expand)

36.Create the new café instance from your AMI. The new instance that you
create must match the following criteria.
o Region: Oregon
o Instance Size: t2.small
o Network: Lab VPC Region 2 , Public Subnet
o IAM Role: CafeRole
o Tag:
 Key: Name
 Value: ProdCafeServer
o Security Group:
 Create a new one named cafeSG, with TCP port 22 open to
anywhere
 Set TCP port 80 so that it's open to anywhere as well
o Proceed without a key pair (the key pair that you created earlier
in this lab should work to connect to it, if necessary)

37.Wait for the new instance to have a Public DNS value assigned to it, even if
the status of the instance is still not Available.

38.Copy the Public DNS value. You will use it soon.


39.To create the needed AWS Systems Manager parameters in the new AWS
Region, complete these steps.
o Return to the AWS Cloud9 IDE in the N. Virginia (us-east-1) Region.
o Open the CafeWebServer/setup/set-app-parameters.sh file in the
text editor.
o Edit line 12 of the file to match this setting:

region="us-west-2"

o Edit line 18 to match this setting (where <public-dns-of-


ProdCafeServer-instance> is the actual DNS of the ProdCafeServer
instance):

publicDNS="<public-dns-of-ProdCafeServer-instance>"

40.Note: The line should still contain the quotation marks, but it should not
contain the angle brackets (< >).

This example shows what line 12 should look like and how line 18 should be formatted. However, the value of
your public DNS will be different.

 File > Save the change.


 To run this script, go to the top of the IDE and choose the Run button.
In the Bash terminal below the text editor, you should see output that's
formatted in JavaScript Object Notation (JSON). This output indicates that the
parameters script ran successfully.

If the script encountered an issue, click here to view troubleshooting tips.

Note: By changing the AWS Region details and running this script again, you
created the same parameters that you created earlier in the us-east-1 Region of
the AWS Systems Manager Parameter Store. However, this time, you created
these parameters in the Oregon Region.

Task 7: Verifying the new café instance


40.Return to the EC2 Console in the Oregon Region, and verify that the new
ProdCafeServer instance is running.

41.Copy the IPv4 public IP address, and load it in a web browser.

The Hello from the cafe web server! message should display.

42.Load the http://<public-ip>/cafe/ URL in a browser tab.

The entire café website should display.

43.Load the Menu page.

The full Menu page should load, and the order-placing functionality should
work.

44.Place an order to verify that the website is working as intended.


45.Troubleshooting tips (skip this one step if you didn't encounter any issues
with loading the Menu page).

The grading script can provide additional tips for parts of the lab that you
didn't complete successfully. You can submit your work as many times as
you like—only the score that you achieve on the last submission will be
retained.

Also, if you want to connect to the new EC2 instance in Oregon (us-west-2)
to do some troubleshooting, run this command from the AWS Cloud9 IDE
in us-east-1:

ssh -i ~/.ssh/id_rsa ec2-user@<public-ip-of-ProdCafeServer>

Note that <public-ip-of-ProdCafeServer> is the actual public IP address of


the ProdCafeServer instance.

You might also like