AWS Builder Center
Why Amazon EC2 Is the Heart of AWS: A Real-World Example with an Online Shop

Why Amazon EC2 Is the Heart of AWS: A Real-World Example with an Online Shop

Learn what Amazon EC2 is, why it is one of the most important AWS services, and how it works in real life, using a festival-sale online shop example with load balancing and auto scaling, plus how to launch your first instance.

Introduction

If you are new to AWS, you will hear about many services: S3, Lambda, RDS, Bedrock. But one service comes up again and again: Amazon EC2.
EC2 (Elastic Compute Cloud) gives you virtual servers in the cloud. In simple words, it is a computer you rent from AWS, and you decide how powerful it is, what runs on it, and how long you keep it.

Why EC2 is so important

Every application needs somewhere to run. EC2 is the most flexible place to run it.
  • Full control: you choose the operating system (Linux or Windows), the CPU, memory and storage, and you install whatever software you want.
  • Pay for what you use: you can start and stop servers whenever you need, instead of buying hardware.
  • Many sizes: there are instance types for general apps, memory-heavy databases, compute-heavy jobs and GPU workloads such as AI.
  • It scales: you can run one server or hundreds, and add or remove them as demand changes.
  • It connects to everything: EC2 works with S3, RDS, load balancers, monitoring and more. Many other AWS services also use EC2 as their compute option, for example ECS and EKS.
That is why EC2 is often called a building block of AWS: learn it well and many other services become easier to understand.

Real-time example: an online shop during a festival sale

Imagine you run a small online shop selling clothes. On normal days you get about 100 visitors an hour. Then you announce a festival sale, and suddenly 10,000 people visit at the same time.

Without the cloud

You would have to buy many servers in advance. On normal days most would sit idle, wasting money. If you buy too few, the website crashes during the sale, and you lose customers.

With EC2

  1. Web server on EC2: your shop's website runs on an EC2 instance, for example a small t3.micro or t3.small.
  2. Database: orders and products are stored in Amazon RDS, and product images in S3.
  3. Load balancer: an Application Load Balancer spreads visitors across several EC2 instances so no single server is overloaded.
  4. Auto Scaling: you set a rule like "if average CPU goes above 60%, add another instance". During the sale, AWS launches extra instances automatically. When traffic drops, it removes them.
  5. Monitoring: CloudWatch watches CPU and sends you an alert if something goes wrong.
Result: the site stays fast during the sale, and after the sale you are not paying for extra servers.

EC2 building blocks you should know

TermSimple meaning
InstanceOne virtual server
AMIA template (operating system + software) used to launch an instance
Instance typeThe size of the server, such as t3.micro
EBS volumeThe hard disk attached to the instance
Security groupA virtual firewall that controls who can connect
Key pairThe file you use to log in securely over SSH
Elastic IPA fixed public IP address

Ways to pay for EC2

  • On-Demand: pay by the hour or second, with no commitment. Best for learning and unpredictable workloads.
  • Savings Plans / Reserved: commit for 1 or 3 years for a lower price. Best for steady workloads.
  • Spot: use spare AWS capacity at a big discount, but AWS can take it back. Best for flexible jobs.

Hands-on: launch your first EC2 instance

  1. Sign in to the AWS Console and open EC2.
  2. Click Launch instance.
  3. Give it a name, for example my-first-server.
  4. Choose an AMI, such as Amazon Linux.
  5. Choose a free-tier eligible instance type, such as t2.micro or t3.micro, depending on your region.
  6. Create a key pair and download the file.
  7. In network settings, allow SSH (port 22) only from your IP, not from everywhere.
  8. Click Launch instance.
  9. Connect with EC2 Instance Connect or SSH.
Optional: install a web server so you can see a page in your browser.
1
2
3
4
5
sudo yum update -y
sudo yum install -y httpd
sudo systemctl start httpd
sudo systemctl enable httpd
echo "<h1>Hello from my first EC2 server</h1>" | sudo tee /var/www/html/index.html
To see the page, you also need to allow HTTP (port 80) in the security group.

When EC2 is not the best choice

  • If you only run small bits of code on demand, Lambda may be cheaper and simpler.
  • If you do not want to manage servers, consider containers (ECS Fargate) or managed services.
EC2 is best when you need control over the environment.

Best practices

  • Never open SSH to the whole internet
  • Use IAM roles instead of storing access keys on the server
  • Take regular snapshots (backups) of important volumes
  • Set a budget and billing alert
  • Stop or terminate instances you no longer need

Cleanup

  1. Terminate the instance (stopping it still keeps the disk, which can cost money)
  2. Delete unused EBS volumes and snapshots
  3. Release any Elastic IP you no longer use

Key takeaways

  • EC2 gives you rentable virtual servers with full control
  • It scales up for busy times and down for quiet times
  • Load balancers and Auto Scaling make it reliable
  • Learning EC2 helps you understand much of the rest of AWS
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article