☁️ The Top 1% Hands-On for Launching an EC2 Instance and Publishing a Web Server: Your First Real AWS Exercise
Introduction
- What You’ll Learn From This Article: Using the knowledge from Understanding EC2 Key Pairs (.pem/.ppk) and Reserved Subnet IPs from a “Top 1%” Perspective, you’ll actually launch an EC2 instance on AWS’s free tier, open only the minimum necessary holes with a security group, SSH in, build a web server (Nginx), and confirm it’s actually reachable over the internet. We’ll also cover the cleanup step that trips people up first on AWS: how to actually stop being billed once you’re done.
- Intended Audience: Readers who’ve created an AWS account but never actually launched an EC2 instance and published a web server from it.
- Estimated Reading Time: About 25 minutes (about an hour if you build along with the hands-on)
This article is part of the Top 1% Series’ full article guide.
Prerequisites
- Understanding EC2 Key Pairs (.pem/.ppk) and Reserved Subnet IPs from a “Top 1%” Perspective: This article assumes you already know how key pairs work.
- An AWS account: Set one up in advance with access to the free tier (12 months, a certain amount of
t2.microinstance time free, and so on). - Basic console operation: The steps below only show the values to configure. If you’re unsure which screen or button to click, reading Hands-On Prep Manual: Basic Operation of the AWS Management Console first is recommended. This article uses the default VPC covered there as-is (with an internet gateway already attached).
- Client machine: The steps below assume you’re working from Windows 11 with PowerShell. If you’re using a Linux/macOS terminal, just substitute the
chmodcommand step.
The Big Picture
This hands-on consists of five steps.
graph LR
Step1["Step1<br/>Create a security group"]
Step2["Step2<br/>Launch an EC2 instance"]
Step3["Step3<br/>Verify the SSH connection"]
Step4["Step4<br/>Build Nginx and publish it"]
Step5["Step5<br/>Clean up (stop billing)"]
Step1 --> Step2 --> Step3 --> Step4 --> Step5
Hands-On Steps
Step 1: Create a security group
From the AWS Management Console, go to EC2 → Security Groups → “Create security group,” and add only these two inbound rules.
| Type | Port | Source |
|---|---|---|
| SSH | 22 | My IP (only your own global IP) |
| HTTP | 80 | Anywhere (0.0.0.0/0) |
Notice that we’re restricting SSH’s source to “My IP” rather than “Anywhere” here. This is the principle covered in Understanding Practical Server Security Measures from a “Top 1%” Perspective — never allow traffic you don’t need — put into practice in a cloud environment via a security group. Leaving SSH (port 22) open to the entire internet is a configuration you should avoid in practice.
Step 2: Launch an EC2 instance
From EC2 → “Launch instance,” launch with the following settings.
- AMI: Ubuntu Server (one covered by the free tier)
- Instance type:
t2.micro(covered by the free tier) - Key pair: Create a new one and download it in
.pemformat (or select an existing one if you already have it) - Security group: Select the one you created in Step 1
Once launched, confirm the instance’s state becomes “running” and that it’s been assigned a public IPv4 address.
Step 3: Verify the SSH connection
Work with the downloaded private key file (<the private key file you created>.pem — the actual filename differs per user) from PowerShell on Windows 11. First, lock down this file’s permissions so nobody but you can read it.
icacls .\<the private key file you created>.pem /inheritance:r
icacls .\<the private key file you created>.pem /grant:r "$($env:USERNAME):(R)"
Next, from that same PowerShell window, connect over SSH using the OpenSSH client built into Windows.
ssh -i .\<the private key file you created>.pem ubuntu@<public IPv4 address>
This icacls command is the operation that locks down permissions — the Windows equivalent of chmod 400 on Linux. Windows 11 comes with an OpenSSH client built in, so the ssh command itself needs no extra install, but since the permission model is entirely different (Windows ACLs, not Linux permission bits), it needs its own dedicated command. Skipping this permission check sometimes doesn’t block the connection on Windows’s OpenSSH client, but locking it down anyway, matching real-world convention, is recommended.
Also notice the username used to connect, ubuntu. An EC2 instance launched from the Ubuntu Server AMI automatically comes with a user named ubuntu created by default, and your first SSH connection is meant to use that user (an Amazon Linux AMI, for comparison, defaults to ec2-user — the default username varies by AMI).
Connecting from a Linux/macOS terminal, or a Linux VM on PVE
If you’re connecting from a Linux/macOS terminal, or from a Linux VM built on PVE per the Hands-On Prep Manual, lock down permissions the traditional way, with chmod.
chmod 400 <the private key file you created>.pem
ssh -i <the private key file you created>.pem ubuntu@<public IPv4 address>
Try to connect without running chmod 400 first, and the connection is refused with a warning: Permissions 0644 for '<filename>' are too open. This is the SSH client itself confirming that the private key file can’t be read by anyone but you.
Step 4: Build Nginx and confirm external access
Once connected via SSH, install and start Nginx.
sudo apt update
sudo apt install -y nginx
sudo apt install alone completes both installing Nginx and configuring it to start automatically (the package bundles its own systemd unit file). Just to be sure, check its status. If you’d like to understand Nginx’s own inner workings (its event-driven architecture, the master/worker processes) in depth, see Understanding How Nginx Works From a “Top 1%” Perspective.
sudo systemctl status nginx
Confirm connectivity locally, from the instance itself.
curl http://localhost/
Success looks like Nginx’s default landing page HTML coming back. Next, confirm access from your own local PC, over the internet.
curl http://<public IPv4 address>/
Visiting the same address in a browser should also show Nginx’s default landing page. At this point, you’ve actually published, with your own hands, a web server that anyone on the internet can reach.
Step 5: Cleaning up (stop the billing)
Once you’re done verifying, terminate the instance. In the EC2 console, select the instance, then “Instance state” → “Terminate instance.”
Important: the difference between "stop" and "terminate," and the invisible billing trap
AWS gives you two ways to stop an instance.
- Stop: Stops the instance from running, but the attached EBS volume (disk) sticks around, and its storage charges keep accruing. You can also restart it later with the same configuration intact.
- Terminate: Completely deletes the instance itself. By default, the root EBS volume is deleted at the same time, and no further charges accrue (though if the EBS volume’s “delete on termination” setting is off, the EBS volume alone can be left behind — watch out for that).
For an instance like this hands-on, built purely for testing with no future use planned, we recommend fully terminating it rather than just stopping it. Also watch out if you ever reserved an Elastic IP (a static public IP) during this process: an Elastic IP is free while it’s attached to a running instance, but once you terminate the instance and it loses its attachment (or if it was never attached at all), billing kicks in. The assumption “I’m not using it, so it must not be costing anything” is one of the most costly misconceptions in AWS. After terminating an instance, always double-check whether any Elastic IP you reserved is still sitting around unattached.
What a Pro Sees Here (Top 1% Understanding)
Why we used the default VPC as-is this time
This hands-on deliberately didn’t create a new VPC — it used the default VPC that AWS automatically sets up when you create an account. The default VPC has every subnet already connected to an internet gateway, with public IPs auto-assigned, making it ideal for today’s goal of “get something on the internet as fast as possible.” In practice, though, the norm is to design a dedicated VPC and subnets per use case, cleanly separating public and private subnets. Continuing to use the default VPC in a production environment is, in practical terms, close to abandoning security design altogether.
A security group is “stateful”
We allowed SSH (port 22) with an inbound rule, but configured nothing at all for outbound (sending response packets back). SSH still works fine anyway, because a security group is stateful — allow traffic in one direction, and the corresponding return traffic is automatically allowed. If you’re used to stateless on-premises firewalls, you might expect to need a separate rule for the return traffic too, but with AWS security groups, that concern doesn’t apply.
Common Misconceptions and Pitfalls
- Misconception 1: “Stopping an instance brings billing down to exactly zero.” Storage (EBS) attached to a stopped instance keeps accruing charges. To stop billing completely, you need to terminate it.
- Misconception 2: “An Elastic IP is free as long as you’re just holding onto it.” An Elastic IP not attached to a running instance accrues charges.
- Misconception 3: “A security group requires you to separately allow outbound traffic too, or the connection won’t work.” A security group is stateful, so return traffic for anything allowed inbound is automatically permitted.
Troubleshooting Perspective
- The SSH connection times out: Check whether the security group’s inbound rule allows port 22, and whether the source matches your current global IP (a home global IP can change over time).
curlcan’t reach it from outside: Check whether the security group allows port 80, and whether Nginx is actually running withsudo systemctl status nginx.- You got charged more than expected: Check the “Billing and Cost Management” dashboard for resources like EBS volumes or an Elastic IP that keep accruing charges even with no instance running.
Summary
- With a security group, the norm is to open only the minimum necessary holes, such as restricting SSH’s source to “My IP.”
- Always lock down the
.pemfile’s permissions before connecting over SSH —icaclson Windows,chmod 400on Linux/macOS. sudo apt install nginxalone completes both the install and the automatic-startup configuration.- Fully stopping billing on an instance requires terminating it, not just stopping it — and watch out, an unattached Elastic IP keeps accruing charges.
- A security group is stateful, so there’s no need to separately allow outbound traffic.
Takeaways to Apply Today
- Once you’re done with an AWS resource you created for testing, always terminate it fully, and double-check nothing like an Elastic IP is left lingering.
- Make it a habit to restrict a security group’s SSH rule to “My IP,” never “Anywhere.”