EC2: Virtual Servers
EC2 (Elastic Compute Cloud) lets you rent virtual servers, called instances. You choose the operating system, size and storage, and it starts in a minute or two.
An EC2 instance is a computer in AWS's data centre that you control completely: you choose Linux or Windows, install any software, and run your website, API or database on it. It's the most flexible option - and also the one where you're responsible for the most: updates, security patches, and keeping your app running.
- AMI: the starting image (for example Amazon Linux or Ubuntu).
- Instance type: the size, such as
t3.micro(small) orm7g.large(bigger). - EBS volume: the server's disk.
- Security group: a firewall that says which ports are open, for example 443 for websites.
- Key pair: used to sign in to the server securely with SSH.
Choosing the instance type is a balance of cost and power. Start small (a t3.micro or t4g.small is enough for a learning project or a small website) and increase the size only if monitoring shows you need it. Security groups are a key safety feature: open only the ports you need, and allow SSH (port 22) only from your own IP address.
Connecting and installing a web server
# connect from your computer (Linux/macOS terminal or Windows PowerShell)
ssh -i my-key.pem ec2-user@<public-ip>
# on the server: install and start a web server
sudo dnf install -y nginx
sudo systemctl start nginxPaying for EC2
- On-Demand: pay by the second, with no commitment.
- Savings Plans / Reserved: commit for 1 or 3 years for a lower price.
- Spot: spare capacity at a big discount, but AWS can take it back.
- EC2 = virtual servers you manage yourself.
- Pick an AMI, an instance type, storage, a security group and a key pair.
- On-Demand, Savings Plans and Spot are different ways to pay.
- Stop or terminate what you don't use.
