AWS Fundamentals Series

☁️ The Top 1% Hands-On for Launching an EC2 Instance and Publishing a Web Server: Your First Real AWS Exercise

Introduction

This article is part of the Top 1% Series’ full article guide.

Prerequisites

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.

TypePortSource
SSH22My IP (only your own global IP)
HTTP80Anywhere (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.

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

Troubleshooting Perspective

  1. 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).
  2. curl can’t reach it from outside: Check whether the security group allows port 80, and whether Nginx is actually running with sudo systemctl status nginx.
  3. 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

Takeaways to Apply Today

  1. 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.
  2. Make it a habit to restrict a security group’s SSH rule to “My IP,” never “Anywhere.”

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).