On this page
On this page
- What Is EC2 (in DOP-C02 Context)
- AMIs (Amazon Machine Images)
- AMI Components
- AMI vs Container Image
- Creating an Encrypted AMI from an Unencrypted One
- Sharing an Encrypted AMI Cross-Account
- Golden AMIs
- EC2 Image Builder
- Components
- Multi-Account Golden AMI Pattern
- User Data
- Private Subnet โ Accessing Artifacts Without Internet
- CloudFormation Bootstrap โ cfn-bootstrap Scripts
- cfn-init and AWS::CloudFormation::Init
- cfn-signal + WaitCondition
- cfn-hup โ Updating Running Instances Without Replacement
- Instance Pricing Models
- Spot Instance Handling
- Instance Profiles โ Compliance at Scale
- Systems Manager Integration
- Session Manager โ Secure Shell Access
- Patch Manager โ Automated Patching
- AWS Health Events โ EC2 Retirement
- Security Groups โ Automated Remediation
- CloudWatch Agent โ OS-Level Monitoring
- EBS (Elastic Block Store)
- Volume Types
- Snapshots
- Encryption
- Instance Metadata Service (IMDSv2)
- Key Exam Scenarios
- CloudWatch Integration
- Automatically Published (AWS/EC2 namespace โ every 5 minutes by default)
- Requires Setup
EC2
EC2 gives you virtual servers in AWS's data centers. You rent compute capacity by the second โ CPU, RAM, and storage โ without buying or maintaining any physical hardware. Within minutes you can have a Linux or Windows server running anywhere in the world.
Why EC2 Exists
Before cloud computing, running a server meant buying hardware, racking it in a data center, waiting weeks for delivery, and paying for it whether you used it or not. EC2 flipped that model. You launch a server when you need it, choose exactly how much CPU and memory it gets, and stop paying the moment you shut it down. For workloads that need a full server environment โ custom software, persistent processes, GPU compute, legacy apps โ EC2 is the right tool.
How It Works
When you launch an EC2 instance, you make three key choices:
AMI (Amazon Machine Image) โ the pre-built template for your server's operating system and software. AWS provides standard AMIs for Amazon Linux, Ubuntu, Windows Server, and others. You can also create your own AMI from an existing instance to bake in your application.
Instance type โ the hardware configuration. Instance types are grouped by use case: general purpose (t3, m6i), compute-optimized (c6i), memory-optimized (r6i), storage-optimized (i3), and GPU (p4, g5). The type determines how many vCPUs, how much RAM, and what network bandwidth you get.
VPC and subnet โ where in your private network the instance lives. An instance in a public subnet can have a public IP and be reached from the internet. One in a private subnet can only be reached from within your network.
Connecting to Your Instance
For Linux instances you connect via SSH using a key pair. For Windows you use RDP. AWS also offers Session Manager (part of Systems Manager), which lets you open a shell in the browser with no open ports at all โ a more secure option for production servers.
Storage
Every EC2 instance gets a root volume for its operating system. You can attach additional EBS (Elastic Block Store) volumes for persistent data โ these survive instance restarts and can be snapshotted. For temporary scratch space, instance store volumes offer very fast local disk but data is lost when the instance stops.
EBS = a USB drive โ attached over the network, survives stop/start, can be snapshotted, unplugged, and moved.
Instance store = a whiteboard bolted to the rack โ blazing fast because it's physically local, but wiped the moment the instance stops or terminates.
The Bigger Picture
EC2 is the building block underneath many higher-level services. ECS runs containers on EC2, Elastic Beanstalk manages EC2 instances on your behalf, and RDS runs database servers on EC2 behind the scenes. Understanding EC2 helps you understand all of them.