Difference between revisions of "Amazon Web Services"

From CSE330 Wiki
Jump to navigationJump to search
 
(24 intermediate revisions by 9 users not shown)
Line 4: Line 4:
  
 
== Creating and Configuring your EC2 Instance ==
 
== Creating and Configuring your EC2 Instance ==
 +
 +
{{RequiredInstructions|content=
  
 
Follow these steps to get to the AWS Management Console:
 
Follow these steps to get to the AWS Management Console:
Line 13: Line 15:
 
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:
 
To create your new virtual machine, click '''Launch Instance'''.  Do the following to configure your instance:
  
# Use the Classic Wizard.
+
# Choose the image labeled "Amazon Linux 2023" from the dropdown list, and make sure you have x86 selected on the right (this should be the default). Also please do not choose any other instance image (for example, do NOT choose the macOS images just because you have a Mac), as selecting the wrong image will cause problems later.  For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].
# Now choose what distribution of Linux you would like to use.  For more information on distributions, refer to [[Linux#Linux Distributions|the Linux guide]].  The following are both good choices, and throughout the wiki, the instructions are equally comprehensive for both.  This semester, we will be teaching this class using Ubuntu, but you are free to use either one.
+
# The default instance variables are all fine.  Click Next until you get to the "Step 6: Configure Security group" screen.
#* Ubuntu Server 12.04 LTS (based on Debian)
+
# Make sure your security group includes a rule of type "SSH", protocol "TCP", port range "22", and source of "0.0.0.0/0" or "Anywhere". If it does not include an SSH rule, click the "Add Rule" button and set the rule accordingly. The security groups you create determine whether a port is open or blocked for your server.
#* Amazon Linux AMI (based on RHEL)
+
#* It might be helpful to change the name for the security group to be more descriptive, such as "CSE330 Instance 1 Security Group" or similar.
# The default instance variables are all fine.  Click Continue until you get to the "Create Key Pair" screen.
+
# Click "Review and Launch", and then "Launch". Then, in the dialog box, create a new Key Pair.  Enter some name for it, and then click "Create & Download your Key Pair".  '''Save your key somewhere secure.'''  In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances. Please note that this is needed to connect to the instance as the root user, and there is no way to download this file again. It is vital you do not lose or delete this file.
# Create a new Key Pair.  Enter some name for it, and then click "Create & Download your Key Pair".  '''Save your key pair somewhere secure that you will be able to access whenever you want to SSH into your server.'''  You will be able to use this key pair for additional instances.
+
# You are now ready to launch your virtual server!  Click "Launch Instances".
# Once you have downloaded your key, set the permissions on it such that only you can read it; that is, the *.pem file you downloaded should have permissions <code>-r--------</code>.  For more information on setting file permissions, refer to [[Linux#File Permissions|the Linux guide]]. (Can you think of any reason why you wouldn't want other people viewing your private key file?)
+
 
# (This step is optional.  The Amazon default group will work fine.) Create a new Security Group.  The security groups you create determine whether a port is open or blocked for your server.
+
}}
#* You need to open the SSH port on your server.  To do this, select "SSH" from the drop-down box, and then click "Add Rule."
 
#: We will be opening more ports by modifying the security group at a later time.  Click Continue.
 
# You are now ready to launch your virtual server!  Click Launch.
 
  
 
== Starting and Stopping your EC2 Instance ==
 
== Starting and Stopping your EC2 Instance ==
Line 29: Line 28:
 
You can start and stop your instance by right-clicking on the instance.  The options are down in the "Instance Lifecycle" section.
 
You can start and stop your instance by right-clicking on the instance.  The options are down in the "Instance Lifecycle" section.
  
'''Note:''' Remember to stop your server instance when you are done using it, for otherwise your account will be charged hourly.
+
=== Amazon EC2 Gives You One Free Micro Instance ===
 +
 
 +
It is free to keep '''''one''''' micro instance running at all times.  The AWS Free Tier includes 750 hours of Micro instance usage per month for a year; given that the longest month is 744 hours long, the Free Tier is enough to keep a single Micro instance running 24/7 for a year.  Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.
  
'''VERY IMPORTANT:''' Never "terminate" your instance, as this PERMANENTLY DELETES the instance- you will lose all your work! Any time you are done using the instance you should instead "stop" the instance and then when you are ready to resume work you should "start" the instance.
+
For additional micro instances, or for larger instances, you will be charged hourly for their use.  One non-free micro instance costs about $14/month; a small instance costs about $43/month.
  
'''Note:''' This is one reason why it is a good idea to commit all your code for various projects to your SVN repository just in case you accidentally terminate your instance.
+
=== Terminate vs Stop ===
  
== Accessing your EC2 Instance via SSH ==
+
Never "terminate" your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead "stop" the instance and then when you are ready to resume work you should "start" the instance.
  
To access your instance via SSH, right click on the icon for the instance and click Connect. You have two options:
+
'''Note:''' Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.
  
# You can use an SSH client on your computer.  Amazon gives you instructions, and even gives you the command you need.  For more information, including how to use SSH on Windows, refer to [[Web Server Configuration#SSH|the Web Server Configuration guide]].
 
# You can use an SSH client that Amazon provides that runs in your browser.
 
  
It will probably be more convenient for you to use an SSH client on your machine so that you do not have to log into AWS every time you want to access your server.  However, which option to use is up to you.
 
  
At first, you will need to SSH into your server using Amazon's default user.
+
=== Reboot vs Stop + Start ===
  
* In the Amazon AMI, the default user is '''ec2-user'''
+
When rebooting your instance using "Reboot", your instance address will not change. When rebooting your instance by clicking "Stop" and then "Start", your address WILL change.
* In Ubuntu 12.04 LTS, the default user is '''ubuntu'''
 
  
To configure your server to allow logins using your own username, refer to [[Web Server Configuration#SSH|the Web Server Configuration guide]].
+
For many assignments, you will need to submit a link to your code running on your instance. If you must reboot your instance, please use "Reboot" rather than the alternative to ensure your link does not become invalid.
  
 
== Enabling Web Access to your EC2 Instance ==
 
== Enabling Web Access to your EC2 Instance ==
  
Once you have configured Apache, you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)
+
{{RequiredInstructions|content=
 +
 
 +
Once you have configured [[Apache]] (which you will do later in this Module), you will need to open up your EC2 instance to web traffic.  (By default amazon blocks all traffic to our instance.)
  
 
Go to the Security Groups under Network & Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.
 
Go to the Security Groups under Network & Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80.  Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.
  
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest "Hello, world!").
+
To make sure things are working, create a file, like '''hello.txt''', in your web server root.  Give it some content (might I suggest "Hello, world!"). The web server root is at /var/www/html
 
 
* In the Amazon AMI, the web server root is at /var/www/html
 
* In Ubuntu 12.04 LTS, the web server root is at /var/www
 
  
 
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].
 
For more information on editing files on the command line, refer to [[Linux#File Editors|the Linux guide]].
  
 
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt
 
You should now be able to visit your server load up the file using your web browser!  Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt
 +
 +
NOTE:depending on the city in which your server is located, your link might look like:
 +
 +
http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt
 +
 +
}}
  
 
[[Category:Module 2]]
 
[[Category:Module 2]]

Latest revision as of 19:11, 12 June 2024

Amazon Web Services provides a method to publish web sites on virtual machines in the "cloud." In CSE330, you will be using an EC2 instance to host your web site.

Before reading this guide, you should be familiar with Linux and the various distributions of Linux. Fore more information, refer to the Linux guide.

Creating and Configuring your EC2 Instance

Follow these steps to get to the AWS Management Console:

  1. Create an AWS account: http://aws.amazon.com/
  2. Sign up for the EC2 Web Service: http://aws.amazon.com/ec2/
  3. Log in to the AWS Management Console

To create your new virtual machine, click Launch Instance. Do the following to configure your instance:

  1. Choose the image labeled "Amazon Linux 2023" from the dropdown list, and make sure you have x86 selected on the right (this should be the default). Also please do not choose any other instance image (for example, do NOT choose the macOS images just because you have a Mac), as selecting the wrong image will cause problems later. For more information on distributions, refer to the Linux guide.
  2. The default instance variables are all fine. Click Next until you get to the "Step 6: Configure Security group" screen.
  3. Make sure your security group includes a rule of type "SSH", protocol "TCP", port range "22", and source of "0.0.0.0/0" or "Anywhere". If it does not include an SSH rule, click the "Add Rule" button and set the rule accordingly. The security groups you create determine whether a port is open or blocked for your server.
    • It might be helpful to change the name for the security group to be more descriptive, such as "CSE330 Instance 1 Security Group" or similar.
  4. Click "Review and Launch", and then "Launch". Then, in the dialog box, create a new Key Pair. Enter some name for it, and then click "Create & Download your Key Pair". Save your key somewhere secure. In addition to using it to authenticate for this instance, you will be able to use the same key for additional instances. Please note that this is needed to connect to the instance as the root user, and there is no way to download this file again. It is vital you do not lose or delete this file.
  5. You are now ready to launch your virtual server! Click "Launch Instances".

Starting and Stopping your EC2 Instance

You can start and stop your instance by right-clicking on the instance. The options are down in the "Instance Lifecycle" section.

Amazon EC2 Gives You One Free Micro Instance

It is free to keep one micro instance running at all times. The AWS Free Tier includes 750 hours of Micro instance usage per month for a year; given that the longest month is 744 hours long, the Free Tier is enough to keep a single Micro instance running 24/7 for a year. Keeping your instance running around the clock will make your life easier, because then you won't need to always change your hostname in your SSH clients.

For additional micro instances, or for larger instances, you will be charged hourly for their use. One non-free micro instance costs about $14/month; a small instance costs about $43/month.

Terminate vs Stop

Never "terminate" your instance, as this PERMANENTLY DELETES the instance! Any time you are done using the instance you should instead "stop" the instance and then when you are ready to resume work you should "start" the instance.

Note: Frequently committing your work to your repository is a safety net in case something horrible happens to your instance.


Reboot vs Stop + Start

When rebooting your instance using "Reboot", your instance address will not change. When rebooting your instance by clicking "Stop" and then "Start", your address WILL change.

For many assignments, you will need to submit a link to your code running on your instance. If you must reboot your instance, please use "Reboot" rather than the alternative to ensure your link does not become invalid.

Enabling Web Access to your EC2 Instance

Once you have configured Apache (which you will do later in this Module), you will need to open up your EC2 instance to web traffic. (By default amazon blocks all traffic to our instance.)

Go to the Security Groups under Network & Security on the EC2 webpage. Select your security group, click on the Inbound Tab. Add a new Custom TCP rule with a Port range of 80. Leave the Source at 0.0.0.0/0 (for all traffic). Click Add Rule, and then click Apply Rule Change.

To make sure things are working, create a file, like hello.txt, in your web server root. Give it some content (might I suggest "Hello, world!"). The web server root is at /var/www/html

For more information on editing files on the command line, refer to the Linux guide.

You should now be able to visit your server load up the file using your web browser! Example Link: http://ec2-xxx-xxx-xxx-xx.compute-1.amazonaws.com/hello.txt

NOTE:depending on the city in which your server is located, your link might look like:

http://ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com/hello.txt