Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. Amazon EC2 reduces the time required to obtain and boot new server instances to minutes, allowing you to quickly scale capacity, both up and down, as your computing requirements change. Amazon EC2 changes the economics of computing by allowing you to pay only for capacity that you actually use.
This lab will walk you through launching, configuring, and customizing a web server on Amazon EC2 using the AWS Management Console.
Let’s get started!
In this lab, you will need to create an EC2 instance using an SSH keypair. The following steps outline creating a unique SSH keypair for you to use in this lab.
Sign into the AWS Management Console and open the Amazon EC2 console.
In the upper-right corner of the AWS Management Console, confirm you are in the desired AWS region (e.g., Sydney).
Click on Key Pairs in the Network & Security section near the bottom of the leftmost menu. This will display a page to manage your SSH key pairs.
To create a new SSH key pair, click the Create Key Pair button at the top of the browser window.
In the resulting pop up window, type [Your Name]-ImmersionDay into the Key Pair Name: text box and click Create.
For Windows users, please select ppk.
You will use the key pair you just created to manage your EC2 instances for the rest of the lab.
In this example, we will launch an Amazon Linux 2 instance, bootstrap Apache/PHP, and install a basic web page that will display information about our instance.
Sign into your AWS Management Console and choose EC2 from the Services menu. Choose Instances in the menu on the left.
Click on Launch instances
In the Quick Start section, click Free tier only and then select the first Amazon Linux 2 AMI for 64-bit (x86) architecture and click Select. Note that the ami-xxxxxxxxx label and specific versions of the installed package may be different than in the image below.
In the Step 2. Choose an Instance Type, select the t2.micro instance size and click Next: Configure Instance Details.
If it isn’t labeled
Free Tier Eligible, you may incur a charge!
User data is a method for bootstrapping your instance - Any code placed here will be executed the first time an instance is launched.
On this page you have the ability to modify or add storage and disk drives to the instance. For this lab, we will simply accept the storage defaults and click Next: Add Tags.
Here, you can choose a “friendly name” for your instance by clicking ‘Add Tag’, and entering “Name” for the Key part and [Your Name] - Web Server for the Value part. This Name key, more correctly known as a tag, will appear in the console once the instance launches. It makes it easy to keep track of running machines in a complex environment. Click Next: Configure Security Group.
You will be prompted to create a new security group, which will be your firewall rules. On the assumption that we are building out a Web server, name your new security group [Your Name] - Web Tier, and confirm an existing SSH rule exists which allows TCP port 22 from Anywhere. Click Add Rule.
Add now another rule with HTTP from the ‘Type’ dropdown menu, and confirm TCP port 80 is allowed from Anywhere (you’ll notice, that “Anywhere is the same as ‘0.0.0.0/0’).
Click the Review and Launch button after configuring the security group.
Review your cofiguration and choices, and then click Launch.
Select the key pair that you created in the beginning of this lab from the drop-down and check the I acknowledge checkbox. Then click the Launch Instances button. Your instance will now be starting, which may take a moment.
Click the View Instances button in the lower right hand portion of the screen to view the list of EC2 instances. Once your instance has launched, you will see your Web Server as well as the Availability Zone the instance is in, and the publicly routable DNS name.
Click the checkbox next to your web server to view details about this EC2 instance.
If it says Initializing, let it finish.
If you click on open address the default behaviour will open a new browser tab directing to https on the instance dns name. Please use http.
You should see a website that looks like the following:
If you don’t see the web page (and you’ve waited a sufficient time for the instance to boot), try rebooting the instance via the console. Can you find it??
To connect to the Linux instance we will use an SSH client. For Windows users, go to the Connecting To Your Linux Instance using PuTTy section below. For Mac users, use the terminal.
Find the instructions to connect to your instance by first selecting your instance and finding the Connect link within the Actions menu. Select SSH client.
Navigate to where your private key is located and enter the following command. Replace the first name and last name with the name you specified prior in step 5 when you created the key.
chmod 400 [FirstName][LastName]-ImmersionDay.pem
Make a note of the Public IP of this EC2 instance
Enter the following command in your SSH client to connect to your Linux instance.
ssh -i "[FirstName][LastName]-ImmersionDay.pem ec2-user@<EC_PUBLIC_IP>
In the Category pane, choose Session.
In the Host Name box enter your public IP.
Set the Port value to 22.
Under Connection type, select SSH.
In the Category pane, expand Connection, expand SSH, and then choose Auth. Complete the following:
.ppkfile that you generated for your key pair and choose Open.
If this is the first time you have connected to this instance, PuTTY displays a security alert dialog box that asks whether you trust the host to which you are connecting.
Choose Yes. A window opens and login as “ec2-user” and you are connected to your instance.
To delete the EC2 instance you created, Select the instance. From the Instance state menu, select Terminate instance.
You will see a pop up window, asking if you are sure you wish to terminate this instance. Click “Terminate”.