Creating an EC2 Linux Instance
- Authors
- Name
- Michael Bui
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
- Go to
EC2
and pressLaunch Instance
- Provide a name and tags (optional)
- Choose a system image (AMI)
- Choose an Instance type (level of compute power)
- Create a key pair if you don't already have one. Choose .ppk for use with PuTTY to ssh into the linux instance
- 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
- 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
- Launch the instance
SSH into Instance
Now we need to connect to our instance
- Go to your Instances and select the instance / click on the instance ID
- To connect to our instance, open PuTTY. Get PuTTY here
- Add the
.ppk
key file you received at time of key creation to PuTTY underConnection
->SSH
->Auth
- Connect to the instance using it's public IP
- The default login name for Amazon Linux instances is
ec2-user
Viewing the Website
- Grab the public IP of the instance
- Go to http://(ip address here)