Creating an EC2 Linux Instance

Authors
  • avatar
    Name
    Michael Bui
    Twitter

Overview

EC2 instances are virtual machines of varying CPU, memory, storage, and networking capacity. They provide flexible resources for your applications.

In this lab, we'll be launching a Linux EC2 Instance running an http web server.

Instructions

Creating EC2 Instance

  1. Go to EC2 and press Launch Instance
  2. Provide a name and tags (optional)
  3. Choose a system image (AMI)
  4. Choose an Instance type (level of compute power)
  5. Create a key pair if you don't already have one. Choose .ppk for use with PuTTY to ssh into the linux instance
  6. Set the network to be the default vpc and create a new security group to allow SSH traffic from your IP & HTTP trafic from the internet
  7. Under advanced settings, paste the following code into user data
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
  • This will install updates for the linux instance & install the http web server
  • This script will only run once when the instance is first started
  1. Launch the instance

SSH into Instance

Now we need to connect to our instance

  1. Go to your Instances and select the instance / click on the instance ID
  2. To connect to our instance, open PuTTY. Get PuTTY here
  3. Add the .ppk key file you received at time of key creation to PuTTY under Connection -> SSH -> Auth
  4. Connect to the instance using it's public IP
  5. The default login name for Amazon Linux instances is ec2-user

Viewing the Website

  1. Grab the public IP of the instance
  2. Go to http://(ip address here)