Amazon EC2 Web Services

From csn
Revision as of 06:23, 13 February 2020 by David (talk | contribs) (Created page with "This lab will introduce you to Amazon EC2 web services. By the end of this lab you will have a virtual machine running at a location of your choosing and serving files via an...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This lab will introduce you to Amazon EC2 web services. By the end of this lab you will have a virtual machine running at a location of your choosing and serving files via an Apache web server. In subsequent weeks we will link this virtual machine to DNS.

This lab assumes that you have viewed the weekly videos and that you have an account with Amazon EC2. The lab is easier to complete in Linux, if you would like a challenge, or plan on completing your final assignment from a Windows PC, you may wish to deploy a Windows image to your workstation.

Log in to the Amazon EC2 Management Console

File:Nocloud.jpg
There is no Cloud

To start the lab, log into the Amazon EC2 management console: http://aws.amazon.com/ec2/

Launch an Ubuntu Machine in EC2

  • Launch a new instance (virtual machine)
    • Follow the steps on the AWS site.
    • Instance type - Pick a "free tier eligible" Ubuntu 18.04 Instance.
    • Configure the instance details - You can leave everything as the default.
    • Add storage - The default is to create a virtual machine with an 8GB hard drive. That's fine, leave it at the default.
    • Add tags - There is no need to add any tags so continue to "Configure Security Group".
    • Configure Security Group
      • Security group name - Call it "ssh-and-web"
      • There is an existing SSH permission that is needed to manage your remote server, that is fine.
      • Click "Add Rule" and select HTTP (web) as the type. This allows web requests to be received by our server.
    • Review and Launch
      • There may be a warning that your server is "open to the world". That's fine, we are building a public webserver!
      • If you are happy with the configuration, click "Launch".
  • Create a new "key pair". AWS uses key files rather than a username and password to verify your identity when logging into your virtual machine. If you lose this file it is unlikely you will be able to mange your virtual machine so it is important to keep it safe. Give it a meaningful name like "webserver-key" so that you can identify it later.
  • Launch Instance - Click on "Launch Instance" and your server will start. After this you can use "View Instance" to monitor it's progress.


Console Access to the Virtual Machine

Now that your server is running in the cloud you need to login to the command line of your virtual machine.

Install Apache

The apt repositories may be out of date before you install anything, it is often a good idea to update them with

sudo apt update

Install the Apache Web Server using:

sudo apt install apache2

Copy files to the Webserver

Once the machine has been launched, modify /var/www/html/index.html to ensure that your page is unique. Browse to your web page using a web browser to ensure it is working. You can find the URL or IP address of your webserver on the AWS console page.

Move some files to your web browser.

If you are using Linux you can use the following command:

scp -i your_pem.pem file_to_upload ubuntu@[dns_entry_or_IP_address]:/home/ubuntu

If you are using windows you will have to use winscp and follow the instructions here:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html#Transfer_WinSCP

This command will move file_to_upload into /home/ubuntu. If you are using a windows I would recommend using SCP winscp.net. Remember that SCP or Secure Copy is using the SSH port (22) to copy files. Once the file has been transferred to /home/ubuntu you can then move the file to /var/www/

If you would like to download files from the Internet straight to your machine, you can use wget.

As an example try:

cd /var/www/html
wget http://www.eecs.berkeley.edu/Pubs/TechRpts/2009/EECS-2009-28.pdf

This command should download the weekly reading into your /var/www/html directory.

If you have difficulties accessing the file via a browser, here are some potential issues:

  • At times Apache has changed the default directory from which it serves HTML. /var/www or /var/www/html are common. One way to find out where the files are being served from is to locate the existing "index.html" file and place your files in the same directory.
  • Rights and ownership can also be an issue.
    • Some Apache installs require the owner to be the user www-data.
    • Check that there are Read rights to the file.

Create Links in index.html

Once these file have been uploaded, you should create links to each file by modifying the HTML in index.html. You can insert the following html into index.html as an example of how to create hyper-links to files.

<a href="pdfs/filename.pdf">Click here</a>

You should ensure that the path for your pdfs matches the path in the shown below. Hint - you may need to add a directory and move some files around. Hints:

mkdir
mv

Test

Test your configuration. Get your lab partner to try to download one of your files. Alternately, try downloading a file via your smartphone or laptop.

Once you have done this successfully, congratulations! You can now access any of the files you uploaded from anywhere in the world. Please do be aware that the web page you have created is not secure and any materials that you upload onto that webpage can be viewed by anyone.

Challenge

  • Try pinging some servers in different parts of the world. Look at the round trip time or latency. Does it match up with your expectations?
  • What are some alternatives to Amazon EC2?

Important!

If you won't be using your instance any more, you may wish to shut down it down or terminate (delete) it to decrease the chances of inadvertently running multiple instances and incurring EC2 usage charges. It is easy to launch instances in different countries and not notice them running. Remember that cloud based services are often billed on the run-time of your server. Be particularly careful if you launch an expensive instance featuring large memory, fast CPUs or GPU processors. It is well worth researching some of the cost limiting features and alerts built in Amazon AWS to avoid a large bill.