# Amazon EC2

> Source: Courseiva IT Certification Glossary — https://courseiva.com/glossary/amazon-ec2

## Quick definition

Amazon EC2 is a core AWS service that provides virtual servers in the cloud. You can create, configure, and manage these virtual machines called instances on demand. You pay only for the compute capacity you use, making it flexible and cost effective for running applications, websites, or data processing tasks.

## Simple meaning

Imagine you run a small bakery and need a kitchen to bake your cakes. You do not want to buy and maintain your own oven, mixer, and refrigerator because they are expensive and take up space. Instead, you rent a professional kitchen for a few hours each week. You only pay for the time you use it. Amazon EC2 works exactly like that, but for computing power. Instead of buying physical servers and setting up a data center, you go to the AWS website and request a virtual server. That virtual server is called an instance. You choose how much processing power, memory, and storage you need. Maybe you need a small instance for a simple website, or a very powerful one for running big data analysis. You can start instances, stop them, and terminate them when you are done. You pay per hour or per second for the time the instance is running. If your bakery gets more customers and you need more ovens, you can easily add more instances. If it is a slow day, you turn them off. This is the core idea of EC2: on demand, scalable, and pay as you go virtual computing. The name EC2 stands for Elastic Compute Cloud. Elastic means you can easily grow or shrink your capacity. Compute refers to processing power and calculations. Cloud means everything runs in AWS data centers, not on your own hardware. For a beginner, think of EC2 as a magic box that can become any computer you need, anytime you want, without any upfront cost or maintenance hassle. You just need an internet connection and an AWS account to get started. It is one of the most popular services on AWS because it gives you complete control over your virtual environment, just like you would have with a physical server, but with much more flexibility.

## Technical definition

Amazon Elastic Compute Cloud (EC2) is a foundational Infrastructure as a Service (IaaS) offering from Amazon Web Services. It provides resizable virtual machines, known as instances, that run on the AWS hypervisor layer, which is a customized version of Xen and later KVM based. Each instance is a virtual server with its own operating system, CPU, memory, storage, and networking capabilities. Users select from various instance families optimized for different workloads: general purpose (like t3 or m5), compute optimized (c5), memory optimized (r5 or x1), storage optimized (i3 or d2), and accelerated computing (p3 or g4) for GPU workloads. Each instance type comes in sizes that scale resources linearly, such as t3.nano, t3.micro, up to t3.2xlarge. EC2 instances are launched from Amazon Machine Images (AMIs), which are preconfigured templates that include an operating system and often additional software. When launching an instance, users specify the AMI, instance type, network settings (VPC, subnet, security groups), storage volumes (Elastic Block Store or instance store), and key pairs for SSH or RDP access. Security groups act as virtual firewalls controlling inbound and outbound traffic at the instance level. EC2 integrates with Elastic Load Balancing (ELB) for distributing traffic across multiple instances and Auto Scaling for automatically adjusting capacity based on demand. Users can connect to instances via SSH for Linux or RDP for Windows. Instance metadata and user data provide configuration information at boot time. EC2 supports multiple purchasing options: On Demand for pay by the hour or second, Reserved Instances for one- or three-year commitments with discounts, Spot Instances for spare capacity at reduced prices but with possible interruption, and Dedicated Hosts for physical server isolation. The service also includes features like Elastic IP addresses for static public IPs, placement groups for controlling instance proximity, and enhanced networking for higher throughput. In real IT environments, EC2 is used to host web servers, application servers, databases, batch processing, machine learning models, and almost any workload that traditionally ran on physical hardware. Performance is monitored through Amazon CloudWatch, which tracks CPU utilization, network traffic, disk I/O, and custom metrics. The service maintains a Service Level Agreement (SLA) of 99.99% availability for instances running in multiple Availability Zones.

## Real-life example

Think of a public library and how you borrow books. In a library, you do not own the books; you borrow them when you need them, read them, and return them. The library has a huge collection of books, but you only take what you need for a limited time. Amazon EC2 works like a digital library for computer power. The library building is the AWS cloud. The library shelves are the vast pool of available compute resources in AWS data centers. Each book in the library is like a virtual machine instance. When you want to read a book, you go to the librarian and fill out a request form. In EC2, you go to the AWS Management Console and launch an instance. The librarian checks the catalog and hands you the book. In AWS, the EC2 service finds an available instance from its resource pool and gives you access. You take the book home and read it. That is like connecting to your EC2 instance via SSH and installing software, running your application, or processing data. While you have the book, nobody else can borrow it. Similarly, while your EC2 instance is running, you have exclusive use of its CPU, memory, and storage. When you finish reading, you return the book to the librarian. In EC2, you stop or terminate the instance, freeing the resources for someone else. If you need a different book, you borrow another one. In EC2, you can launch a different instance type for a different job. The library has many copies of popular books, so multiple people can borrow the same book simultaneously. In AWS, multiple customers can run identical instances from the same AMI at the same time. The library also has special collections like rare manuscripts that only certain members can access. That corresponds to Dedicated Hosts or Reserved Instances for specific compliance needs. If you keep a book too long, the library charges a late fee. In EC2, you are charged for every hour or second your instance runs, so you want to stop it when not in use. This analogy helps you understand that EC2 gives you temporary, on demand access to computing power without the burden of ownership.

## Why it matters

Amazon EC2 is one of the most important services in cloud computing because it replaced the traditional model of buying and maintaining physical servers. Before EC2, companies had to purchase hardware months in advance, install it in data centers, configure networking, and manage power and cooling. This process was slow, expensive, and inflexible. EC2 changed that by letting anyone provision virtual servers in minutes over the internet. For IT professionals, EC2 matters because it provides the compute foundation for almost every other AWS service. When you use AWS Lambda, it runs on EC2 infrastructure. When you deploy an Amazon RDS database, it runs on EC2 instances. When you run an Amazon ECS container, it launches on EC2. Understanding EC2 is essential for designing scalable and resilient cloud architectures. In real IT work, EC2 allows teams to quickly spin up test environments, run proof of concepts, or handle traffic spikes without permanent investment. For example, an e-commerce company can launch hundreds of EC2 instances during Black Friday and terminate them afterward, paying only for what they used. EC2 also enables geographic distribution. You can launch instances in different AWS regions to reduce latency for customers around the world. From a security perspective, EC2 gives you granular control with security groups, network ACLs, and IAM roles. You can isolate instances in private subnets, encrypt volumes, and apply compliance standards. For system administrators, EC2 reduces the operational burden of hardware failures. If an instance fails, you can launch a new one from an AMI in minutes. For developers, EC2 provides consistent environments for development, testing, and production using the same AMI. In cybersecurity, EC2 can be used to run vulnerability scanners, penetration testing tools, or honeypots in isolated environments. Overall, EC2 is the cornerstone of AWS compute, and mastering it is critical for anyone pursuing a career in cloud computing, DevOps, or system administration.

## Why it matters in exams

Amazon EC2 appears in nearly every major cloud certification exam, especially those from AWS but also in Azure and Google exams when comparing services. For the AWS Certified Cloud Practitioner exam, EC2 is a core compute service that you must understand at a conceptual level. Questions often ask about EC2 use cases, pricing models, and basic features like instance types and security groups. For the AWS Certified Developer Associate exam, EC2 questions go deeper into how applications interact with EC2, including instance metadata, user data scripts, and integration with other services like Elastic Load Balancing and Auto Scaling. You may be asked about launching instances from custom AMIs, configuring security groups for web applications, or troubleshooting connectivity issues. For the AWS Solutions Architect Associate exam, EC2 is a major topic. You need to know how to design fault tolerant architectures using multiple EC2 instances across Availability Zones. Questions cover selecting the right instance type for a workload, choosing between storage options like EBS vs instance store, and optimizing costs with Reserved or Spot Instances. You might also see scenario questions about migrating on premises workloads to EC2 or implementing high availability using Auto Scaling groups. For Azure exams like AZ 104 (Azure Administrator) and Azure Fundamentals, EC2 is not directly tested, but you should understand the equivalent service called Azure Virtual Machines. However, cross cloud knowledge helps. The exam may ask you to compare capabilities. For Google Cloud exams like Associate Cloud Engineer and Digital Leader, the analogous service is Compute Engine. Knowing EC2 helps you understand these parallels. In all these exams, EC2 questions often appear as multiple choice scenario based items. For instance, the question might describe a company that needs to run a CPU intensive batch job for two hours every night and asks for the most cost effective EC2 purchasing option. The correct answer would be Spot Instances. Another question might describe a web application that must remain available if one Availability Zone fails, and you need to choose an architecture that uses EC2 instances in multiple zones behind an Elastic Load Balancer. The correct answer involves an Auto Scaling group with a minimum of two instances across two zones. Understanding EC2 thoroughly will help you answer these questions accurately and quickly.

## How it appears in exam questions

EC2 questions in certification exams fall into several common patterns. The first is scenario based selection of the appropriate instance type. For example, a question might describe a video transcoding application that needs high GPU performance. You must choose from options like t3.large, c5.xlarge, p3.2xlarge, or r5.large. The correct answer is p3.2xlarge, which is GPU optimized. Another pattern involves purchasing options. A question could say a company runs a production database 24/7 for three years and wants the lowest cost. Options include On Demand, Reserved Instances, Spot Instances, or Dedicated Hosts. The best answer is Reserved Instances with a three year term, all upfront. Another common pattern is security group configuration. A question might show a web server on EC2 that needs HTTP and HTTPS access from the internet. The answer is a security group rule allowing inbound traffic on ports 80 and 443 from 0.0.0.0/0. A variation adds SSH access only from a specific IP. Then there are availability and fault tolerance questions. A scenario could describe an application that must survive the failure of one Availability Zone. Options include launching all instances in one zone, launching instances across two zones with a load balancer, or using a single larger instance. The correct architecture uses at least two Availability Zones. Auto Scaling questions are also frequent. A question might ask what happens when CPU utilization exceeds a threshold. Answer: Auto Scaling launches a new EC2 instance. Another pattern involves storage. A question could compare EBS backed vs instance store backed instances. If the instance fails, instance store data is lost, but EBS data persists. You need to choose the appropriate one for stateless vs stateful applications. Networking questions ask about placing EC2 instances in public vs private subnets. A web server should be in a public subnet, while a database should be in a private subnet. There are also questions about EC2 and IAM roles. For example, an application on EC2 needs to access S3. You attach an IAM role to the instance rather than storing credentials. Finally, there are cost optimization questions. You might be asked to reduce costs for a development environment that runs only 8 hours a day. The answer is to stop instances during non working hours or use scheduled Auto Scaling. These patterns show that EC2 knowledge is tested from multiple angles, so you need a well rounded understanding.

## Example scenario

A startup called GreenLeaf Analytics builds a web application that analyzes weather data for farmers. The application is new and has unpredictable traffic. Some days 100 farmers use it, other days 10,000 farmers log in after a storm warning. The startup needs to run their application on the cloud. They choose Amazon EC2. They create an AMI with their web application code, a Linux operating system, and a database client. They launch a t3.medium instance for initial testing. As the user base grows, they move to a t3.large instance. During harvest season, traffic spikes. They set up an Auto Scaling group that launches additional EC2 instances when CPU utilization exceeds 70 percent. When traffic drops, Auto Scaling terminates the extra instances. They also place an Elastic Load Balancer in front of the instances to distribute requests evenly. To save money, they use On Demand instances for the baseline and Spot Instances for the extra capacity during spikes. The database runs on a separate EC2 instance in a private subnet with only the web instances allowed to connect. Security groups restrict SSH access to the office IP address. The startup monitors cost using AWS Cost Explorer and sets up CloudWatch alarms for high CPU. This scenario shows how EC2 provides flexibility, scalability, and cost control for a growing application. The startup does not need to buy servers or predict traffic months in advance. They simply use EC2 to adjust compute capacity on the fly.

## Common mistakes

- **Mistake:** Thinking that stopping an EC2 instance terminates it and you lose all data.
  - Why it is wrong: Stopping an instance simply shuts it down, but the EBS root volume and attached data volumes persist. You can start the instance again later with the same data. Terminating is what deletes the instance and by default deletes the root volume.
  - Fix: Remember that stop is like turning off your laptop. You can turn it back on and everything is still there. Terminate is like throwing the laptop away.
- **Mistake:** Believing all EC2 instances have public IP addresses by default.
  - Why it is wrong: By default, an instance launched in a default VPC gets a public IP. But in a custom VPC, you must explicitly assign a public IP or use an Elastic IP. Many enterprise VPCs are private with no public access.
  - Fix: Always check the VPC and subnet settings. Instances in private subnets do not get public IPs. Use a NAT gateway or bastion host if internet access is needed.
- **Mistake:** Assuming that changing an instance type can be done while the instance is running.
  - Why it is wrong: You must stop the instance before you can change its instance type. The instance must be in the stopped state to modify the instance type. After changing, you start it again.
  - Fix: Always stop the instance before resizing. Plan for a brief downtime if you need to change instance types for a production system.
- **Mistake:** Confusing Security Groups and Network ACLs.
  - Why it is wrong: Security groups are stateful firewalls at the instance level, while Network ACLs are stateless firewalls at the subnet level. Beginners often apply rules to one but expect behavior of the other.
  - Fix: Security groups control traffic to and from a specific instance. NACLs control traffic entering and leaving an entire subnet. Use security groups for instance level control and NACLs for subnet wide rules.
- **Mistake:** Using the root user for everyday tasks on an EC2 instance.
  - Why it is wrong: The root user on Linux has unrestricted access. Using it for routine work can lead to accidental system damage or security risks. Best practice is to create a user with sudo privileges and use that for daily tasks.
  - Fix: Create a new user with limited permissions and assign them to a group with sudo access. Only use root for system administration tasks when absolutely necessary.

## Exam trap

An exam question states you need to maintain the same private IP address for an EC2 instance after it is stopped and started. The options include Elastic IP, but that is for public IPs. Beginners might choose Elastic IP. Read the question carefully. Private IP addresses in a VPC are retained by default when you stop and start an instance, as long as the instance is in the same subnet. No extra service is needed. Elastic IP is for public IP persistence. Remember that private IPs are tied to the network interface, which remains attached.

## Commonly confused with

- **Amazon EC2 vs Amazon Lightsail:** Lightsail is a simplified version of EC2 for beginners. It offers preconfigured plans with fixed pricing, including compute, storage, and data transfer. EC2 gives you granular control over every resource and a pay as you go model. Lightsail is great for simple websites or small applications, while EC2 is for complex enterprise workloads. (Example: If you want to host a personal blog, Lightsail is easier to set up. If you need to run a custom machine learning model with specific GPU instances, use EC2.)
- **Amazon EC2 vs AWS Elastic Beanstalk:** Elastic Beanstalk is a Platform as a Service (PaaS) that automatically handles the deployment, scaling, and monitoring of your application on EC2 instances. With EC2, you manage everything yourself, including the OS, software, and scaling. Elastic Beanstalk is for developers who want to focus on code, while EC2 is for those who need full control. (Example: To deploy a Node.js app without managing servers, use Elastic Beanstalk. To customize the underlying server with custom security patches, use EC2 directly.)
- **Amazon EC2 vs AWS Lambda:** Lambda is a serverless compute service that runs code in response to events without provisioning servers. EC2 requires you to launch and manage virtual servers. Lambda is for short running, event driven functions. EC2 is for long running or stateful applications. (Example: For resizing an image every time it is uploaded to S3, use Lambda. For running a 24/7 e commerce website with a database, use EC2.)
- **Amazon EC2 vs Azure Virtual Machines:** Azure VMs are Microsoft's equivalent of EC2 in the Azure cloud. Both provide IaaS virtual machines. The key difference is the platform, pricing model, and integration with other services. EC2 uses AMIs, while Azure uses managed images or custom VHDs. If you are studying for Azure exams, understand EC2 to compare with Azure VMs. (Example: If you need a Windows server in AWS, you launch an EC2 Windows AMI. In Azure, you create a Windows VM from the Azure Marketplace. The concept is the same, but the tools and terminology differ.)

## Step-by-step breakdown

1. **Choose an Amazon Machine Image (AMI)** — An AMI is a template that contains the operating system and sometimes preinstalled software. You select an AMI based on your needs, like Amazon Linux, Ubuntu, or Windows Server. The AMI determines the initial state of your instance.
2. **Select an instance type** — Instance types define the hardware of the virtual machine, including CPU cores, memory, and network performance. You choose based on your workload. For a web server, a general purpose t3 instance may suffice. For data analytics, a compute optimized c5 instance is better.
3. **Configure network settings** — You specify which VPC and subnet the instance launches into. You also attach security groups that act as firewalls. You decide whether the instance gets a public IP and whether it can receive traffic from the internet. This step determines network connectivity.
4. **Add storage** — You attach storage volumes to the instance. The root volume contains the operating system. You can add extra EBS volumes for data. You choose volume type, size, and whether encryption is needed. Storage persists even after stopping the instance unless you choose instance store.
5. **Configure security and access** — You create a key pair for SSH access to Linux instances or set a password for Windows. You assign an IAM role to the instance so applications can access other AWS services securely. You also configure user data scripts to run at launch for automated setup.
6. **Launch the instance** — After reviewing all settings, you launch the instance. AWS provisions the virtual machine in a few minutes. You receive a public IP or DNS name to connect. The instance moves through pending state to running state.
7. **Connect and manage** — You connect to the instance using SSH for Linux or RDP for Windows. You install software, transfer files, and configure applications. You can also use AWS Systems Manager to manage instances without opening SSH ports.
8. **Monitor and scale** — You use CloudWatch to monitor metrics like CPU utilization and network I/O. You set up alarms to notify you of issues. You can automate scaling with Auto Scaling groups that launch or terminate instances based on demand.
9. **Stop or terminate when done** — If you need to pause work, you stop the instance. You are not charged for the instance hours while stopped, but you still pay for storage. When you no longer need the instance, you terminate it. Termination deletes the instance and by default deletes the root volume.

## Practical mini-lesson

To work effectively with Amazon EC2, you must understand the lifecycle of an instance and the options available at each step. Start by creating an AMI for your application. You can use an AWS provided AMI or create your own by customizing an instance and then creating an image from it. This ensures consistency across environments. When launching, always use IAM roles for granting permissions to instances rather than hard coding credentials. This is more secure and easier to manage. For production workloads, choose a Reserved Instance if you have predictable usage. For variable or short term workloads, use On Demand. For batch processing or fault tolerant applications, use Spot Instances to save up to 90 percent. Be aware that Spot Instances can be terminated with a two minute warning, so design your application to handle interruptions. Storage is another critical consideration. EBS volumes are persistent and can be snapshotted for backup. Instance store provides high performance but data is lost on stop or termination. Use instance store for temporary data like caches or scratch space. For high availability, spread your instances across multiple Availability Zones. Use an Elastic Load Balancer to distribute traffic and Auto Scaling to maintain desired capacity. Security groups are stateful, so if you allow inbound traffic on port 443, the response is automatically allowed. Network ACLs are stateless, so you must explicitly allow both inbound and outbound traffic. A common best practice is to use security groups for instance level control and NACLs as a second layer for subnet protection. For connecting to instances, prefer AWS Systems Manager Session Manager over SSH if possible, as it does not require opening inbound ports and logs all commands. Also, tag your instances with meaningful names and environment labels to stay organized in large accounts. Finally, set budgets and alerts to avoid surprise bills. EC2 costs can add up quickly if you leave instances running idle. Use instance scheduler to stop non production instances during off hours. By mastering these practical aspects, you will be able to use EC2 efficiently and securely in real IT environments.

## Memory tip

Think of EC2 as a rental car: you pick the model (instance type), drive it (run your workload), return it (stop or terminate), and pay only for the time you used it. You never own the car, but you have full control while you drive.

## FAQ

**How does EC2 pricing work?**

EC2 has several pricing models. On Demand charges per hour or per second with no commitment. Reserved Instances require a one or three year term for a discount. Spot Instances let you bid on spare capacity for big savings but can be interrupted. There are also Dedicated Hosts and Savings Plans.

**Can I change the operating system of a running EC2 instance?**

No, you cannot change the operating system of a running instance. You must launch a new instance with a different AMI that contains the desired OS. You can migrate your data to the new instance.

**What is the difference between stopping and terminating an EC2 instance?**

Stopping an instance shuts it down but preserves the EBS volumes and instance metadata. You can start it again later. Terminating permanently deletes the instance and by default deletes the root EBS volume. Stopping incurs no compute charges, but you still pay for storage.

**How do I connect to my EC2 instance?**

For Linux instances, you connect using SSH with a key pair. For Windows, you use Remote Desktop Protocol (RDP) with a password. You can also use AWS Systems Manager Session Manager for browser based access without opening inbound ports.

**What is an Amazon Machine Image (AMI)?**

An AMI is a preconfigured template that contains the operating system and often additional software. You use an AMI to launch an EC2 instance. You can use AWS provided AMIs, community AMIs, or create your own custom AMI from an existing instance.

**Can I move my EC2 instance to a different Availability Zone?**

You cannot directly move a running instance to a different Availability Zone. You need to create an AMI from the instance, then launch a new instance in the target Availability Zone using that AMI. You can also use an Elastic IP to reassign the public IP.

**What is the maximum number of EC2 instances I can run?**

By default, AWS accounts have a soft limit of 20 On Demand instances per region. You can request a limit increase through the AWS Support Center. For Spot Instances, limits vary by instance type and region.

**How do I back up my EC2 instance?**

You can back up an EC2 instance by creating a snapshot of its EBS volumes. You can also create an AMI from the instance, which captures the entire configuration including attached volumes. These backups can be used to restore the instance in case of failure.

## Summary

Amazon EC2 is the core compute service of AWS that provides resizable virtual servers in the cloud. It allows you to launch instances with various combinations of CPU, memory, storage, and networking to match your workload requirements. You pay only for what you use, making it cost effective for businesses of all sizes. EC2 supports multiple pricing models including On Demand, Reserved, and Spot Instances, giving you flexibility in managing costs. It integrates deeply with other AWS services like Elastic Load Balancing, Auto Scaling, and CloudWatch to build scalable and resilient applications. For certification exams, you must understand instance types, purchasing options, security groups, and high availability architectures. Common mistakes include confusing stop and terminate, assuming all instances get public IPs, and misapplying security groups vs NACLs. Remember that EC2 is about renting compute power on demand, similar to borrowing a book from a library. This core concept underpins many other AWS services and is essential for any cloud professional. With proper understanding, you can design, deploy, and manage efficient cloud solutions using Amazon EC2.

---

Practice questions and the full interactive page: https://courseiva.com/glossary/amazon-ec2
