Amazon EC2 Basics: Launch Your First Virtual Server, Instance Types, Key Pairs, Security Groups and Connecting

AWS Technical Essentials 55 min min read Updated: Nov 17, 2026 Beginner
Amazon EC2 Basics: Launch Your First Virtual Server, Instance Types, Key Pairs, Security Groups and Connecting
Beginner Topic 1 of 4

What Is EC2?

Amazon Elastic Compute Cloud (EC2) gives you virtual servers (called instances) in the cloud. You choose the operating system, size and software, and pay per second while the instance runs.

  • Think of an instance as a computer you rent, ready in about a minute
  • Used for web servers, applications, databases, batch jobs and more
  • You are responsible for the guest operating system (updates, software)

Parts of an Instance Launch

ChoiceMeaningBeginner pick
AMI (Amazon Machine Image)Template with the operating system and softwareAmazon Linux 2023 (or Ubuntu, Windows)
Instance typeCPU and memory sizet3.micro or t2.micro (Free Tier eligible where offered)
Key pairPublic/private key used to log in over SSHCreate one and download the .pem safely
Network settingsVPC, subnet (AZ), public IP, security groupDefault VPC, public subnet, allow SSH from your IP only
StorageEBS volume for the disk8 GiB gp3 root volume
IAM instance profileRole for the serverOptional, for S3 access without keys
User dataA script that runs on first bootInstall a web server automatically

Instance Type Families

FamilyGood forExample names
General purposeBalanced CPU and memory, web serverst3, t4g, m6i, m7g
Compute optimizedCPU-heavy work, batch, game serversc6i, c7g
Memory optimizedBig databases, in-memory cachesr6i, x2
Storage optimizedHigh disk speed, data warehousesi4i, d3
Accelerated computingMachine learning, graphics (GPU)p4, g5, inf2

Name reading: m6i.large = family m, generation 6, processor option i (Intel), size large. Letter g means AWS Graviton (Arm), often cheaper for the same work.

Launch With the Console

  1. Open EC2 → Launch instance and give it a name tag
  2. Choose Amazon Linux 2023 AMI
  3. Choose t3.micro
  4. Create a key pair (RSA, .pem) and download it
  5. In Network settings, allow SSH (22) from My IP and HTTP (80) if you will run a website
  6. Keep the default 8 GiB storage
  7. Open Advanced details → User data and paste the script below
  8. Click Launch instance, then wait for 2/2 status checks passed
bash #!/bin/bash # User data: runs once as root on first boot dnf update -y dnf install -y nginx systemctl enable --now nginx echo "<h1>Hello from my first EC2 server</h1>" > /usr/share/nginx/html/index.html

Launch With the CLI

bash # Find the latest Amazon Linux 2023 AMI id from the public SSM parameter AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 --query 'Parameters[0].Value' --output text) aws ec2 create-key-pair --key-name my-key --query KeyMaterial --output text > my-key.pem && chmod 400 my-key.pem aws ec2 create-security-group --group-name web-sg --description "web and ssh" aws ec2 authorize-security-group-ingress --group-name web-sg --protocol tcp --port 80 --cidr 0.0.0.0/0 aws ec2 authorize-security-group-ingress --group-name web-sg --protocol tcp --port 22 --cidr 203.0.113.9/32 aws ec2 run-instances --image-id $AMI --instance-type t3.micro --key-name my-key --security-groups web-sg \ --user-data file://userdata.sh --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=first-server}]' aws ec2 describe-instances --filters Name=tag:Name,Values=first-server --query 'Reservations[].Instances[].[InstanceId,State.Name,PublicIpAddress]' --output table

Connect to the Instance

MethodHowNotes
SSHssh -i my-key.pem ec2-user@<public-ip>Needs port 22 open and the key. ec2-user for Amazon Linux, ubuntu for Ubuntu
EC2 Instance ConnectBrowser-based connect button in the consoleEasy for quick access
Session ManagerConsole or aws ssm start-session --target <id>No open port 22 and no key. Needs the SSM role. Best practice
RDPRemote Desktop to port 3389For Windows servers

Instance Lifecycle

ActionWhat happensCharged?
StopShuts down. Disk (EBS) is keptNo compute charge, EBS storage still charged. Public IP changes
StartBoots againCompute billing resumes
RebootRestart, same machineSame
HibernateSaves memory to disk, resumes laterNeeds encrypted root volume
TerminateDeletes the instance (root disk deleted by default)Charges stop. Cannot be undone
Avoid surprise bills A stopped instance still pays for its EBS disk, and an unattached Elastic IP or public IPv4 address may cost money. When finished practicing, terminate instances and delete extra volumes and IPs.

Key Extras

  • Elastic IP: a fixed public IPv4 address that you can move between instances
  • Instance metadata: the server can read info about itself at 169.254.169.254 (use IMDSv2 tokens)
  • Tags: labels like Name=web, env=dev for organization and billing
  • Status checks: system (AWS side) and instance (your OS) checks every minute
  • Termination protection: stops accidental terminate

Practice

  1. Launch the nginx server from the console and open its public IP in the browser
  2. Connect with SSH and run uptime and df -h
  3. Stop and start it and notice the public IP change
  4. Attach an IAM role and use Session Manager instead of SSH
  5. Terminate everything and confirm no instances remain

Conclusion

EC2 gives virtual servers. Choose an AMI, instance type, key pair, security group and storage, use user data for first-boot setup, connect with SSH or better Session Manager, understand stop vs terminate, and clean up after practice.

Quick Summary: what; launch choices; families; console; CLI; connecting; lifecycle; extras.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators