
Getting Started with Amazon EC2: A Beginner's Hands-On Guide
A practical, beginner-friendly guide to Amazon EC2 — covering AMIs, instance types, security groups, key pairs, and the hands-on lessons learned from launching a real instance on AWS.
Getting Started with Amazon EC2: A Beginner's Hands-On Guide
Introduction
When I first heard the term "cloud computing," I imagined something vague and abstract — servers somewhere in the sky doing mysterious things. That changed the moment I spun up my first Amazon EC2 instance.
EC2, short for Elastic Compute Cloud, is one of AWS's most foundational services. It lets you rent virtual servers — called instances — on demand, without buying or maintaining physical hardware. Whether you're hosting a web application, running a script, or experimenting with a Linux environment, EC2 is often where the journey begins.
In this article, I'll walk you through what EC2 is, how it works, and the key things I learned through both the AWS Skill Builder Introduction to EC2 lab and my own hands-on experiments. If you're new to AWS, this is a great place to start.
What Is Amazon EC2?
Amazon EC2 gives you resizable compute capacity in the cloud. Instead of buying a physical server, you configure and launch a virtual machine in minutes. You only pay for what you use.
Here are a few key concepts you'll encounter right away:
Term | What It Means |
|---|---|
Instance | A virtual server running in AWS |
AMI (Amazon Machine Image) | A template that contains the OS and software configuration |
Instance Type | Defines the hardware specs (CPU, RAM, storage) of your instance |
Security Group | A virtual firewall that controls inbound and outbound traffic |
Key Pair | An SSH key used to securely connect to your instance |
Elastic IP | A static public IP address you can assign to your instance |
Step 1: Choose Your AMI
When you launch an EC2 instance, the first thing you choose is the Amazon Machine Image (AMI). Think of it as the "starting template" for your virtual server — it defines the operating system and any pre-installed software.
For most beginners, the Amazon Linux 2023 AMI or Ubuntu Server are solid choices. Both are free-tier eligible and well-documented.
Tip: If you're exploring cybersecurity or penetration testing, you might eventually want to look at community AMIs with Kali Linux pre-installed — but start with the basics first.
Step 2: Select an Instance Type
Your instance type determines how powerful your virtual machine will be — CPU cores, RAM, and networking capacity. AWS organizes instance types into families:
- t-series (t3, t4g) — General purpose, burstable. Perfect for learning and low-traffic workloads.
- m-series — Balanced compute and memory. Good for general applications.
- c-series — Compute optimized. Useful for CPU-intensive tasks.
- r-series — Memory optimized. Great for databases and caching.
For the lab and beginner use cases, the t2.micro (free-tier eligible) is your best friend. It gives you 1 vCPU and 1 GB RAM — more than enough to explore EC2 basics.
Step 3: Configure Your Instance
Before launching, AWS lets you configure several important settings:
Network and Subnet
You'll place your instance inside a VPC (Virtual Private Cloud) — essentially your own private network in AWS. Choose the default VPC to keep things simple at first.
IAM Role (Optional but Important)
Attaching an IAM role to your instance allows it to interact with other AWS services (like S3 or CloudWatch) without embedding credentials directly. This is a best practice even in learning environments.
User Data
One of my favorite features. The User Data field lets you pass a shell script that runs automatically when the instance first boots. You can use this to install software, update packages, or configure services — all without logging in manually.
Here's a simple example that installs and starts a web server:
#!/bin/bashyum update -yyum install -y httpdsystemctl start httpdsystemctl enable httpdecho "<h1>Hello from EC2!</h1>" > /var/www/html/index.html
This script runs at launch, so your web server is ready by the time you connect.
Step 4: Set Up a Security Group
Security Groups are EC2's built-in firewall. They control what traffic can reach your instance and what your instance can send out.
By default, all inbound traffic is blocked. You need to explicitly allow what you need:
Rule | Port | Use Case |
|---|---|---|
SSH | 22 | Connect to Linux instance via terminal |
HTTP | 80 | Serve web traffic (unencrypted) |
HTTPS | 443 | Serve web traffic (encrypted) |
RDP | 3389 | Connect to Windows instance |
Custom | Any | App-specific ports |
Security note: Avoid setting your SSH source to0.0.0.0/0(open to the world) in production. During labs it's fine, but in real environments, restrict SSH access to your IP address only — or better, use AWS Systems Manager Session Manager to avoid opening port 22 at all.
Step 5: Create a Key Pair
To SSH into a Linux EC2 instance, you need a key pair. AWS stores the public key on your instance, and you keep the private key (a
.pem file) on your local machine.When connecting:
chmod 400 your-key.pemssh -i "your-key.pem" ec2-user@<your-public-IP>
Important: You cannot download the private key after creation. Store it somewhere safe immediately. If you lose it, you'll need to create a new key pair and replace the instance.
Step 6: Launch and Connect
Once you review and launch, AWS provisions your instance in seconds. You'll see it move from Pending → Running in the EC2 dashboard.
To connect:
- Go to EC2 > Instances
- Select your instance and click Connect
- Choose EC2 Instance Connect (browser-based, no key needed) or use SSH with your
.pemfile
Once connected, you're inside a real Linux server running in AWS infrastructure. It's a genuinely exciting moment the first time it happens.
What I Learned from the Skill Builder Lab
The AWS Skill Builder Introduction to EC2 lab walks you through launching an instance with a web server using User Data. Here's what stood out to me beyond the click-through steps:
1. The power of User Data automation
Watching a web server start automatically — without me touching anything — made automation feel real and tangible. It clicked for me why DevOps teams script everything: repeatability beats manual effort every time.
2. Security Groups are stateful
You only define inbound rules, and responses to allowed traffic are automatically permitted. This is different from traditional firewalls (like iptables) where you'd manage both directions. Understanding this prevents a lot of "why can't I connect?" confusion.
3. Stopping vs. Terminating
- Stop: Instance shuts down. Data on the EBS volume is preserved. You can restart later.
- Terminate: Instance is permanently deleted (including storage, by default).
This distinction matters a lot. I've seen people accidentally terminate instances they meant to stop.
4. Public IP changes on restart
By default, your instance's public IP changes each time you stop and start it. If you need a persistent IP (for a web server, for example), attach an Elastic IP.
Key Takeaways
If you're just getting started with EC2, here's what I'd summarize:
- EC2 = rent a virtual server. Choose your OS (AMI), hardware specs (instance type), and network settings.
- Security Groups are your first line of defense. Be intentional about what ports you open.
- User Data is powerful. Automate your setup from the first boot.
- Understand the difference between stop and terminate. One is reversible. One isn't.
- Use the Free Tier. The
t2.microinstance gives you 750 hours/month free — more than enough to learn.
What's Next?
EC2 is just the starting point. Once you're comfortable launching and connecting to instances, here are natural next steps:
- Amazon S3 — Store files your EC2 instance can access
- Elastic Load Balancing — Distribute traffic across multiple EC2 instances
- Auto Scaling — Automatically adjust capacity based on demand
- AWS Systems Manager — Manage instances without opening SSH ports
- Amazon VPC — Design more complex, secure network architectures
Final Thought
Cloud computing isn't magic — it's infrastructure you can learn, control, and reason about. EC2 was my first real "aha" moment with AWS: the idea that I could have a running server, globally accessible, in under two minutes, without owning any hardware.
If you haven't launched your first EC2 instance yet, go do it. The AWS Free Tier gives you everything you need to get started at zero cost.
I'll be writing more about cloud and cybersecurity topics as I continue my studies. Stay tuned.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article