Lab: Launch a Virtual Web Server

Acadestine

Learning Objectives
    • Select an Amazon Machine Image (AMI) suitable for hosting a lightweight Linux web server.
    • Configure an EC2 User Data script to automatically bootstrap an HTTP web server on launch.
    • Configure Security Group inbound rules to open Port 80 for public HTTP web traffic.
    • Validate server deployment and connectivity by retrieving the live web page via public IP.

What You Need Before Launching

Now that you know Amazon EC2 is the ideal compute service for hosting a flexible, long-running web server, it is time to prepare your launch environment. Before spinning up a virtual server, you must confirm three foundational cloud building blocks are in place.

To ensure a smooth deployment, you need to understand how these three prerequisites fit together:

  • AWS Management Console Access: The AWS Management Console is the web-based graphical interface used to visually create, manage, and monitor your cloud resources. You need active console access with sufficient permissions to deploy computing and networking components.
  • VPC Subnet Basics: A VPC (Virtual Private Cloud) acts as your isolated virtual network in AWS, while a subnet is a distinct section of that network assigned a specific range of IP addresses. For a web server to communicate with external visitors, it must reside inside a public subnet connected to the internet.
  • Security Group Fundamentals: A security group operates as a virtual firewall that strictly controls the incoming and outgoing network traffic for your Amazon EC2 instance. By default, a security group blocks all inbound traffic from the outside world until you explicitly add rules to permit it.

With your console access ready, an established VPC subnet available, and an understanding of security group firewalls, you are fully equipped to build your target architecture.

Your Target: A Live Web Server in Minutes

With your console access ready, an established VPC subnet available, and an understanding of security group firewalls, you are fully equipped to build your target architecture. But before we start building in the console, let's lock in a clear visual model of our exact destination.

Imagine launching a digital pop-up shop. In a traditional environment, setting up a web server requires buying physical hardware, installing an operating system, and manually executing dozens of configuration commands. In the cloud, automated cloud web server hosting allows you to deploy a fully functional, publicly accessible web server in a matter of minutes without touching a single physical machine.

The Finished Architecture

When our lab build is complete, your target environment will consist of three core components working in perfect synchronization:

  • The Compute Engine: An EC2 virtual server running live inside your isolated VPC subnet.
  • The Automated Payload: An automated boot routine that installs web server software and writes a custom home page the second the server boots up requiring zero manual software installation.
  • The Perimeter Gate: An inbound rule on your security group virtual firewall that opens the door for public HTTP traffic from the internet.

From Zero to Live via Automation

In traditional IT setups, provisioning a new server was a slow, manual chore. You had to log into the machine, download software packages, start services, and troubleshoot permissions. In AWS, we replace manual labor with automated server bootstrapping.

Think of automated cloud deployment like ordering a smart pre-fabricated house: the moment the home lands on its foundation (your VPC subnet), it automatically plugs into power, unlocks its front gate (security group), and turns on the kitchen lights all before you even step through the front door.

By defining your software instructions ahead of time, AWS provisions the virtual hardware, boots the operating system, executes your setup script, and starts serving web traffic immediately. Once complete, anyone with your server's public IP address will be able to load your live web page from anywhere in the world.

With the end goal clearly visualized, let's look at the blueprint of how these pieces fit together behind the scenes.

Mapping the Web Server Blueprint

With the end goal clearly visualized, let's look at the blueprint of how these pieces fit together behind the scenes. Before launching hardware in the cloud, cloud architects map out how execution steps and network rules sequence together.

Understanding this blueprint prevents mysterious errors later, such as trying to access a web server before it finishes installing, or finding a server blocked by network firewalls.


The EC2 Instance Lifecycle Flow

When you tell AWS to launch a virtual server, your EC2 instance doesn't instantly jump to serving web pages. It moves through a clear sequence of lifecycle states:

  1. pending: AWS provisions physical hardware in the specified subnet, assigns a network interface, and reserves virtual resources.
  2. Bootstrapping: While still initializing, the operating system boots up and runs automated setup tasks.
  3. running: The virtual machine is fully booted, initial scripts have completed, and the server is ready to accept user connections.

Understanding this state transition is vital because automated setup scripts only execute during the initial boot phase.


User Data Script Execution Sequence

To build a fully working web server automatically, AWS uses a feature called User Data. This is a script you supply during launch that runs automatically as the operating system starts up.

The User Data execution sequence follows strict operational rules:

  • Single-Run Execution: The script runs exactly once by default during the initial launch boot cycle. It will not re-run on subsequent reboots.
  • Root Administrator Privileges: The script executes with root system permissions. This allows it to update package repositories, install services like Apache, and modify system files without requiring manual password prompts.
  • Non-Interactive Bootstrapping: Because no human is logged in during boot, the script must run entirely automated without expecting user prompts or inputs.

By the time the EC2 instance transitions into the running state, your User Data script has already finished installing and starting the web server service.


Traffic Ingress via Port 80

Once the instance reaches the running state and the web server process is active, the network boundary must be configured to accept visitors.

When a client enters your server's public network address into a browser, the client attempts an HTTP connection over Port 80, the standard networking port for unencrypted web traffic.

text [ Client Browser ] ---> ( Request via Port 80 ) ---> [ Security Group Firewall ] ---> [ EC2 Web Server ]

Traffic moving into your instance is called ingress traffic. Here is how that request travels into your server:

  1. The Ingress Request: The browser sends an HTTP request targeting Port 80 of your server's public interface.
  2. The Firewall Check: The request hits the security group acting outside your instance. The security group evaluates its inbound rules.
  3. Rule Evaluation: If an inbound rule explicitly allows incoming traffic on Port 80, the firewall lets the packet pass through. If no matching rule exists, the traffic is blocked at the firewall boundary, and the user experiences a connection timeout.
  4. Application Handshake: Once past the firewall, the request reaches the VPC network interface and hits the web server software listening internally on Port 80.

Blueprint Component Summary

Component / Phase Timing / Role Primary Responsibility
pending State Initial Launch Allocates underlying AWS hardware, storage, and network interfaces inside your target subnet.
User Data Script Boot Phase (Once) Installs system updates, installs web server packages, and starts the web service automatically as root.
running State Post-Boot Operational Represents a fully initialized virtual machine ready to handle active workloads.
Port 80 Ingress Rule Continuous Network Guard Permits incoming public web traffic (HTTP) to cross the security group perimeter.

With the entire blueprint mapped from initial launch to public network traffic entry, you are ready to start configuring the actual components, starting with selecting the base operating system image.

Step 1: Choose Your OS Base (Selecting an AMI)

With the entire blueprint mapped from initial launch to public network traffic entry, you are ready to start configuring the actual components, starting with selecting the base operating system image.

Before you can spin up a virtual machine in the cloud, AWS needs to know what operating system and software foundation to load onto your server's root storage volume. In the AWS ecosystem, this foundational blueprint is known as an AMI (Amazon Machine Image).

Think of an AMI as a pre-packaged disk image containing a fully configured operating system (OS), architecture parameters (like 64-bit x86 or ARM), and pre-installed system tools. Without an AMI, your EC2 instance is just raw, unformatted virtual compute power with nowhere to boot.

text +-------------------------------------------------------------+ | Amazon Machine Image | | (AMI) | | +--------------------+ +------------------+ +---------+ | | | Operating System | | Architecture | | System | | | | (Amazon Linux 2023)| | (64-bit x86/ARM) | | Tools | | | +--------------------+ +------------------+ +---------+ | +-------------------------------------------------------------+ | v [ Boots Virtual Machine Instance ]

Understanding Amazon Linux 2023

While AWS offers dozens of operating systems including Ubuntu, Red Hat, Windows Server, and macOS Amazon Linux 2023 is the recommended Linux distribution for modern AWS workloads. It is engineered specifically by AWS to provide a secure, stable, and high-performance execution environment for cloud applications.

Here are the primary characteristics that make Amazon Linux 2023 ideal for our server base:

  • AWS Integration: It comes pre-loaded with AWS command-line tools and repository links, ensuring seamless integration with cloud infrastructure services.
  • Modern Package Management: It utilizes dnf (Dandified YUM) as its package manager, allowing you to install server software like the Apache HTTP server easily and reliably.
  • Hardened Security: Features deterministic updates, pre-configured security policies, and standard Linux security frameworks like SELinux enabled by default.
  • Optimized Boot Performance: Built with lightweight kernel configs to ensure your instance transitions from pending to running as fast as possible.

SCREENSHOT REQUIRED: AWS EC2 Launch Instance wizard highlighting the selection of Amazon Linux 2023 AMI with the "Free Tier eligible" tag visible

Selecting Free Tier Eligible Resources

When you open the AWS Management Console and navigate to the EC2 Launch Wizard, you will be presented with the Quick Start menu for selecting your image and hardware specs. To avoid unnecessary charges while learning, always select options clearly labeled "Free Tier eligible".

While the AMI defines the software baseline, you must also select an instance type, which defines the hardware specs (CPU cores and RAM capacity). For our web server deployment, we will pair Amazon Linux 2023 with a micro-sized compute instance.

Selection Parameter Recommended Choice Why We Select It
Amazon Machine Image Amazon Linux 2023 AMI Pre-configured, secure, and maintained directly by AWS.
Architecture 64-bit (x86) Standard platform architecture with wide software compatibility.
Instance Type t2.micro or t3.micro Provides Free Tier compute resources sufficient for lightweight web hosting.

By picking these baseline options in the console interface, you establish a cost-free, lightweight operating system foundation ready to be turned into a functional web server. Now that your base virtual machine OS is locked in, it's time to ensure you don't have to log in and manually install software after it boots up.

Step 2: Automate Server Setup with User Data

Now that your base virtual machine OS is locked in, it's time to ensure you don't have to log in and manually install software after it boots up.

In cloud computing, initializing a machine by automatically loading software, code, and configurations during initial launch is known as bootstrapping. Instead of launching a blank Linux machine, logging in via a terminal, and manually typing commands, AWS allows you to hand the server a set of instructions to execute automatically the moment it spins up.


What is EC2 User Data?

When launching an Amazon EC2 instance, AWS provides a dedicated field called User Data.

Think of User Data as a pre-flight checklist or standard script that you hand to the virtual machine before pressing the power button. EC2 User Data scripts execute with root administrator privileges automatically during the very first boot cycle of the instance.

SCREENSHOT REQUIRED: Expanding the Advanced Details section at the bottom of the EC2 Launch Wizard to reveal the blank User Data text entry box

By utilizing a simple shell script inside the User Data field, you can turn a plain Linux installation into a fully functioning web server in seconds without ever opening a remote command line.


The Automation Script

To transform our Amazon Linux 2023 instance into an active web server, we will use a bash script. Scroll down to the bottom of the EC2 Launch Wizard, expand the Advanced Details panel, locate the User Data text box, and enter the following script:

bash

!/bin/bash

Update installed packages

dnf update -y

Install Apache HTTP Server

dnf install -y httpd

Start the Apache web service

systemctl start httpd

Configure Apache to auto-start on server reboots

systemctl enable httpd

Create custom home page content

echo "

Hello World from AWS EC2!

" > /var/www/html/index.html


Breaking Down the Script Mechanics

Every line in this script performs a distinct administrative task. Understanding what happens behind the scenes helps demystify how automated provisioning works:

Script Line Command Purpose
#!/bin/bash Known as a shebang. It tells the operating system that this file must be executed using the bash shell interpreter.
dnf update -y Updates package lists and security updates. The -y flag automatically answers "yes" to confirmation prompts.
dnf install -y httpd Installs Apache HTTP Server (httpd), which is the software responsible for serving web content over the network.
systemctl start httpd Starts the web server service immediately once installation finishes.
systemctl enable httpd Registers the Apache service to start up automatically if the underlying virtual machine ever reboots.
echo "..." > /var/www/html/index.html Generates your home page. Writes the standard <h1> header text into Apache's default web directory (/var/www/html/).

Important Behavior Rules for User Data

As you work with User Data, keep these essential operational rules in mind:

  • Runs Once Only: By default, User Data scripts run only during the first launch of the EC2 instance. Stopping and starting the instance later will not trigger the script again.
  • Elevated Privileges: The script runs automatically as the superuser (root). You do not need to prefix commands with sudo inside the User Data box.
  • Silent Execution: Because the script runs headlessly in the background while the instance boots, there is no interactive terminal prompt. All commands must include non-interactive flags like -y.

Your server is now programmed to install Apache and build a web page the exact second it turns on but right now, nobody on the internet can actually reach it.

Step 3: Open the Front Door (Configuring Port 80)

Your server is now programmed to install Apache and build a web page the exact second it turns on but right now, nobody on the internet can actually reach it.

By default, Amazon Web Services operates on a strict zero-trust model. When you create a new server, AWS locks down all incoming traffic to protect your instance from unauthorized access. Think of your instance as a vault: even if you run a restaurant inside, customers can't enter if the front door is welded shut. To let web visitors view your new site, you must explicitly open that front door by configuring a Security Group.


What is a Security Group?

A Security Group acts as a virtual firewall that controls the traffic allowed to reach and leave your EC2 instance. It evaluates traffic at the instance level before packets ever touch your operating system.

When configuring traffic rules, you work with two directional categories: * Inbound Rules: Filter traffic coming into your instance from the outside world. * Outbound Rules: Filter traffic originating from your instance heading out to the internet (by default, all outbound traffic is allowed).

Because AWS blocks all incoming network requests by default, your web server will silently ignore any web browser trying to connect. To fix this, you must manually create an Inbound Rule inside your launch wizard's Network settings.


Understanding Protocols and Ports: The Web's Front Door

Network traffic relies on standard channels called ports. If an IP address is like a building's physical address, a port number is like an individual apartment door number.

Different services listen on different ports: * Unencrypted web traffic relies on the HTTP protocol, which communicates over Port 80. * When a user types your IP address into a web browser, the browser automatically attempts to establish a connection through Port 80.

To host a functional web application, you must configure your Security Group to listen specifically for HTTP traffic traveling through Port 80.

SCREENSHOT REQUIRED: AWS EC2 Launch Wizard Network Settings panel showing Security Group Inbound Rules configured for HTTP on Port 80 from 0.0.0.0/0


The 0.0.0.0/0 Rule: Granting Public Access

When you add a rule to open Port 80, AWS asks a crucial question: Who should be allowed through this port?

You define this using an IP address range. To allow literally anyone on the internet to view your website, you use the Classless Inter-Domain Routing (CIDR) notation 0.0.0.0/0.

Rule Setting Selection / Value What It Actually Means
Type HTTP Automatically selects the network protocol standard for web browsing.
Port Range 80 Locks the rule strictly to incoming web traffic on channel 80.
Source Type Anywhere-IPv4 Configures the network source to 0.0.0.0/0.
Source Range 0.0.0.0/0 Represents every single IPv4 address in the entire world.

Setting your source to 0.0.0.0/0 makes your application globally accessible. While you would restrict administrative ports (like SSH) to your personal IP address, a public web server requires 0.0.0.0/0 so public visitors can load your site.


Step-by-Step: Adding the Rule in the Console

Inside the EC2 Launch Wizard, scroll to the Network settings section and execute the following:

  1. Under Auto-assign public IP, ensure it is set to Enable (this provides your instance with a publicly reachable network address).
  2. Select Create security group.
  3. Locate the Allow HTTP traffic from the internet checkbox and check it. (Alternatively, click Add security group rule, set the Type to HTTP, and set the Source to Anywhere-IPv4).

With your AMI chosen, your User Data script pasted, and Port 80 opened to 0.0.0.0/0, your server blueprint is complete. You are ready to launch your instance and broadcast your website to the world.

Test Drive: Confirming Your Live Site

With your instance launched and its virtual front door unlocked, it is time for the moment of truth. Your server is actively running in an AWS data center, but to see it in action, you need to find its unique address on the global internet.

Step 1: Locate Your Server's Public IPv4 Address

Just like a physical store needs a street address so customers can find it, your virtual server needs a Public IPv4 address to receive traffic from the web. AWS automatically assigns this address to your instance upon launch.

To find your instance's public IP address, follow these steps in the AWS Management Console:

  • Navigate to the EC2 Dashboard and click on Instances (running).
  • Select your newly launched web server instance from the list by clicking the checkbox next to it.
  • Look at the Details pane at the bottom of the screen.
  • Locate the field labeled Public IPv4 address and copy the string of numbers (for example, 54.210.12.199).

SCREENSHOT REQUIRED: EC2 Console Instances table highlighting the selected instance and the Public IPv4 address field in the Details tab below

Step 2: Test the Connection in Your Browser

Now that you have your server's address, you can test the connection directly from your web browser.

Open a new browser tab, paste your Public IPv4 address into the address bar, and press Enter. Because you opened Port 80 for standard HTTP traffic, ensure your URL starts with http:// rather than https://. Most modern web browsers automatically attempt to prepend https:// (which uses Port 443), so explicitly typing http:// ensures your request routes to the correct port you opened in your Security Group.

text http://

Step 3: Verify the Bootstrapped Web Page Output

If your server launched successfully and your script executed properly, your browser will immediately render the web page generated by your User Data script during launch.

When you hit Enter, a fast chain reaction occurs behind the scenes:

  1. Your browser sends an HTTP request across the public internet targeted at your Public IPv4 address on Port 80.
  2. The request hits your instance's virtual firewall (Security Group), which inspects the traffic and grants entry because of your 0.0.0.0/0 inbound rule.
  3. The request reaches your EC2 instance and is picked up by the Apache web server software installed during boot.
  4. Apache reads the index.html file created by your User Data script and sends the HTML content back to your browser.

Seeing your custom text render on the screen confirms that every layer of your infrastructure from the OS base to the firewall and automated software installation is fully operational. You have successfully transformed raw cloud compute into a live, publicly accessible web server.

Fixing Common Launch & Connection Blunders

You have successfully learned how to transform raw cloud compute into a live, publicly accessible web server. But what happens when you paste that Public IPv4 address into your browser, press Enter, and the loading icon just spins endlessly until it times out?

In the cloud world, a non-responsive server is rarely a mystery it is almost always the result of a misconfigured cloud setting. Learning to systematically diagnose and resolve launch blunders is what separates novice button-mashers from confident AWS engineers.


Diagnosing HTTP Connection Timeouts

When your browser displays a connection timeout error, it means your computer sent a request out into the internet, but it never received a response back from your instance.

It is vital to distinguish a connection timeout from an immediate error page: * Connection Timeout (Infinite Spinning): Your network packets are being silently blocked or dropped before they reach the web server process. The browser waits patiently until it eventually gives up. * Connection Refused or 404 Not Found: Your network request successfully reached the virtual machine, but the operating system actively rejected it or the web server software could not find the requested file.

If you encounter an infinite spinner, your primary suspect is a network filter dropping incoming traffic. However, before adjusting network rules, you must first verify that the virtual machine itself is actually up and running.


Checking Instance Running State and Health Checks

Your web server cannot respond to web requests if the underlying virtual machine is powered off, booting up, or experiencing hardware issues.

To confirm the foundational health of your server in the AWS Management Console:

  1. Navigate to the EC2 Dashboard and select Instances.
  2. Locate your instance and inspect the Instance state column.
  3. Inspect the Status check column.

text +-------------------+-----------------+-----------------------+ | Instance State | Status Check | System Health Meaning | +-------------------+-----------------+-----------------------+ | running | 2/2 checks passed| Server is healthy | | pending | Initializing | Server is still booting| | stopped | 0/2 checks passed| Server is powered off | +-------------------+-----------------+-----------------------+

Your instance state must be running with 2/2 checks passed before expecting any web content to load.

The Status check field consists of two distinct automated tests: * System Status Check: Monitors the physical AWS infrastructure hosting your virtual machine. If this fails, AWS is experiencing underlying hardware or power issues. * Instance Status Check: Monitors the operating system and internal boot configuration of your individual instance. If this fails, the operating system may have crashed during boot.

If your state is running and you see 2/2 checks passed, your virtual machine hardware and operating system are healthy. If the browser still times out, you must look at your traffic filters.


Verifying Security Group Port 80 Inbound Rules

The single most common reason for an HTTP timeout on a freshly launched Amazon EC2 instance is a missing or misconfigured Security Group rule.

Remember that an AWS Security Group acts as a strict, stateful firewall that blocks all inbound traffic by default unless an explicit allow rule exists. If you forgot to open Port 80 during the launch wizard, AWS will silently discard every web request sent to your server.

To inspect and fix your firewall rules:

  1. Select your instance in the EC2 Console.
  2. Click on the Security tab in the lower panel.
  3. Click the link under Security groups to open its configuration.
  4. Select the Inbound rules tab and verify the presence of an active HTTP rule.

Your inbound rules table must contain an exact match for public web traffic:

Type Protocol Port Range Source Purpose
HTTP TCP 80 0.0.0.0/0 Allows public web access from anywhere on the internet

If the Port 80 rule is missing, click Edit inbound rules, add the rule for HTTP with source 0.0.0.0/0, and save changes. The update applies instantly no server reboot required. Refresh your browser page, and your bootstrapped web site will load immediately.

Previous Next Lesson