๐งพ AWS Billing, Budget, and Cost Management โ Step-by-Step
1. Access the Billing Console
- In the AWS Management Console, click your account name (top right).
- Choose Billing and Cost Management.
โ ๏ธ If you see โAccess Deniedโ โ you are using an IAM user.
Only the root account can enable billing access for IAM users.
2. Enable Billing Access for IAM Users
- Sign in as the root account owner.
- Go to Account โ IAM user and role access to billing information.
- Turn ON โActivate IAM access.โ
Now IAM users with admin permissions can view billing.
3. View Billing Data
- Go back to Billing โ Bills.
-
You can now see:
- Month-to-date costs
- Forecasted cost
- Charges by service (e.g., EC2, S3, etc.)
Click on a month โ scroll to Charges by Service to identify what costs money (e.g., NAT Gateway, EBS, etc.).
4. Check the Free Tier
- Go to Billing โ Free Tier.
-
Shows:
- Usage vs Free Tier limit
- Forecasted overages
If usage turns red, youโre about to be charged โ stop or delete resources.
5. Create a Budget
- Go to Billing โ Budgets โ Create budget.
- Choose โUse a template (simplified)โ.
Option A: Zero Spend Budget
- Template: Zero spend
- Name:
My Zero Spend Budget
- Alert email: your address (e.g.,
yourname@example.com
) - Sends alert as soon as you spend $0.01.
Option B: Monthly Cost Budget
- Template: Monthly cost budget
- Limit: e.g.,
$10
- Add alert recipients.
-
Alerts at:
- 85% of actual spend
- 100% of actual spend
- 100% of forecasted spend
โ Result
Youโll get an email warning if:
- You spend 1 cent (zero spend budget), or
- Your forecasted/actual spend hits your limit.
This ensures students donโt overspend during AWS labs.
โ๏ธ Amazon EC2 โ Elastic Compute Cloud
1. What is EC2?
- EC2 = Elastic Compute Cloud
- Itโs AWSโs main Infrastructure as a Service (IaaS) offering.
- Lets you rent virtual machines (VMs) โ called EC2 Instances โ on demand.
- Foundation of AWS: most AWS services depend on EC2 behind the scenes.
2. Key EC2 Components
Component | Description |
---|---|
EC2 Instance | The virtual server you rent from AWS. |
EBS Volume | Elastic Block Storage โ a network-attached disk for your instance. |
Elastic Load Balancer (ELB) | Distributes incoming traffic across multiple instances. |
Auto Scaling Group (ASG) | Automatically increases or decreases the number of running instances based on demand. |
Security Group | Acts as a firewall โ controls inbound/outbound traffic to the instance. |
Elastic IP | A static public IP address you can attach to your instance. |
User Data | Script that runs once when the instance boots โ used for automation/setup tasks. |
3. Choosing EC2 Instance Settings
When launching an EC2 instance, you choose:
Option | Examples / Details |
---|---|
Operating System | Linux (most popular), Windows, or macOS. |
Compute (vCPUs) | Choose instance type (e.g., t2.micro , t3.medium ) based on performance. |
Memory (RAM) | Depends on workload size (web server vs. database). |
Storage | - EBS: network-attached, persistent storage. - Instance Store: local hardware disk (temporary). |
Network | Select subnet, VPC, and network interface (speed, public IP, etc.). |
Firewall Rules | Configure Security Groups โ open only necessary ports (e.g., 22 for SSH, 80 for HTTP). |
4. Bootstrapping with User Data
Bootstrapping = running setup commands automatically when the instance launches.
โ Common tasks in User Data:
- Update packages (
yum update -y
orapt update -y
) - Install software (e.g., Nginx, Apache, Python)
- Download configuration files
- Start services automatically
๐ง Notes:
- Runs only once at first boot.
- Executed as root user (no need for
sudo
). - Makes EC2 setup automated and repeatable.
Example:
#!/bin/bash
yum update -y
yum install -y nginx
systemctl start nginx
systemctl enable nginx
echo "<h1>Hello from EC2</h1>" > /usr/share/nginx/html/index.html
5. Why EC2 Matters
- Core building block of the AWS ecosystem.
- Lets you quickly deploy servers on demand.
- Forms the base for many other services (ECS, EKS, Beanstalk, etc.).
- Teaches the foundation of cloud computing: scalability, pay-as-you-go, and automation.
๐ Launching Your First EC2 Instance (Amazon Linux)
1. What Youโll Do
You will:
- Launch your first EC2 instance (a virtual server).
- Use User Data to automatically install a web server.
- Access the website through a browser.
- Learn to start, stop, and terminate the instance.
2. Launch an Instance
Step 1: Open EC2 Console
- Go to AWS Management Console โ EC2 โ Instances
- Click Launch Instances
Step 2: Name and Tags
- Name:
My First Instance
- (Tag Key =
Name
, Value =My First Instance
)
Step 3: Choose an AMI (Amazon Machine Image)
- Go to Quick Start โ Amazon Linux 2 AMI (64-bit x86)
- โ Free Tier eligible
This defines the operating system for your EC2 instance.
Step 4: Choose Instance Type
- Choose t2.micro (Free Tier eligible)
- 1 vCPU, 1 GB RAM
- Perfect for small practice servers
Step 5: Create or Choose Key Pair
Youโll need a key to connect via SSH later.
- Name:
EC2Tutorial
- Type:
RSA
-
Format:
- .pem โ for Mac, Linux, or Windows 10+
- .ppk โ for older Windows (PuTTY)
Download and save it safely โ AWS will not let you download again!
Step 6: Configure Network Settings
- Leave defaults (public IP assigned automatically).
- Create a Security Group (default name:
launch-wizard-1
). -
Add inbound rules:
- SSH (port 22) โ Source: Anywhere
- HTTP (port 80) โ Source: Anywhere (This allows browser access.)
Step 7: Configure Storage
- Default: 8 GB gp2 EBS volume
- You get up to 30 GB free under Free Tier.
- Option โDelete on Terminationโ = Yes (keeps cleanup simple).
Step 8: Add User Data Script
Scroll to Advanced details โ User data
Paste this script:
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
This will:
- Update the system
- Install Apache web server
- Enable it at boot
- Create a simple โHello Worldโ web page
Step 9: Launch
- Review โ Launch instance
- Go to View all instances
- Wait until Instance State = running (takes ~10โ15 seconds)
3. Access the Website
- Copy your Public IPv4 address
- In your browser, enter:
http://<Public-IP>
- (โ ๏ธ Use
http
, nothttps
.) - Youโll see: Hello World from 172.x.x.x โ where the number is the private IP.
4. Manage the Instance
Action | What It Does | Note |
---|---|---|
Stop Instance | Shuts down the server | Youโre not billed while stopped |
Start Instance | Restarts it later | โ ๏ธ May get a new public IP |
Terminate Instance | Deletes server + volume | Irreversible โ removes data |
๐ง The private IP stays the same, but the public IP changes after every stop/start cycle unless you assign an Elastic IP.
5. Key Takeaways
- You can launch a web server in minutes without owning hardware.
- User Data automates setup during boot.
- Learn to stop/terminate to avoid charges.
- EC2 is the core of cloud computing โ flexible, fast, pay-as-you-go.
โ๏ธ Amazon EC2 Instance Types
1. Why EC2 Instance Types Exist
AWS offers different EC2 instance types to match different workloads โ
from lightweight web servers to machine learning and databases.
Each type has:
- Different CPU, RAM, and network capabilities
- Different optimization (compute, memory, storage, or networking)
- Different pricing
2. EC2 Instance Naming Convention
Example: m5.2xlarge
Part | Meaning | Example |
---|---|---|
m | Instance class / family |
m = general purpose |
5 | Generation |
5 = newer than 4 , older than 6
|
2xlarge | Size | Larger = more vCPUs & memory |
So m5.2xlarge
means:
โก๏ธ General-purpose instance, generation 5, with 2xlarge size (moderate CPU and memory).
3. EC2 Instance Families (Main Categories)
Type | Family Prefix | Description | Example Use Cases |
---|---|---|---|
๐งฉ General Purpose |
t , m , a
|
Balanced CPU, memory, and networking | Web servers, code repos, dev/test environments |
โก Compute Optimized | c |
High CPU performance | Batch processing, media encoding, gaming, ML inference |
๐ง Memory Optimized |
r , x , z
|
High RAM for in-memory processing | Databases, caching (Redis), analytics, BI |
๐พ Storage Optimized |
i , d , h
|
High local disk throughput | Big data, OLTP, NoSQL, data warehousing |
๐ฎ Accelerated Computing |
p , g , f
|
GPUs or FPGAs | AI/ML training, deep learning, rendering, HPC |
4. Common Instance Examples
Instance | vCPU | Memory (GB) | Optimized For |
---|---|---|---|
t2.micro |
1 | 1 | General-purpose, free tier |
m5.large |
2 | 8 | Balanced web/app server |
c5.4xlarge |
16 | 32 | Compute-intensive tasks |
r5.16xlarge |
64 | 512 | Memory-heavy databases |
i3.8xlarge |
32 | 244 | Storage-optimized, high IOPS |
5. Helpful Reference Websites
๐ AWS Official Instance Types Page
https://aws.amazon.com/ec2/instance-types
โ Lists all current instance families, pricing, and features.
๐ EC2Instances.info
https://ec2instances.info
โ Excellent for:
- Comparing CPU, memory, storage, and cost
- Searching & filtering instance families
- Quickly checking On-Demand and Reserved pricing
6. Key Takeaways
โ Understand the prefixes:
-
t
โ test & dev (burstable) -
m
โ general-purpose -
c
โ compute-heavy -
r
โ memory-heavy -
i
โ storage-heavy -
p/g
โ GPU-based
โ Choose instance type by workload:
- Web apps โ
t2.micro
,m5.large
- Databases โ
r5.xlarge
- Machine learning โ
p3
,g4
- Data warehousing โ
i3
,d2
โ Use the AWS Free Tier:
-
t2.micro
ort3.micro
= Free for 12 months (750 hours/month)
๐ Security Groups in Amazon EC2 (Firewalls)
1. What Are Security Groups?
- Security Groups (SGs) are virtual firewalls that control traffic into and out of your EC2 instances.
-
They define network access rules based on:
- Ports (e.g., 22 for SSH, 80 for HTTP)
- Protocols (TCP, UDP, etc.)
- Source/Destination (IP ranges or other security groups)
๐ง Think of a security group as a โprotective shieldโ that decides who can talk to your server and on which ports.
2. Basic Behavior
Direction | Default Behavior | Purpose |
---|---|---|
Inbound | โ All traffic blocked by default | Protects the instance from unwanted access |
Outbound | โ All traffic allowed by default | Lets the instance connect to the internet (updates, downloads, etc.) |
- SGs contain only ALLOW rules (no explicit โdenyโ).
- If traffic is not explicitly allowed โ itโs implicitly denied.
3. How Security Groups Work
Example:
You (your computer) are on the public internet, trying to connect to an EC2 instance.
- The EC2 instance has a Security Group attached.
-
That SG checks its inbound rules:
- If your IP and port (e.g., 22 or 80) match โ traffic allowed
- If not โ traffic blocked
Two traffic directions:
- Inbound rules โ from the outside โ into EC2
- Outbound rules โ from EC2 โ out to the internet
4. Security Group Rules Format
Field | Description | Example |
---|---|---|
Type | What kind of connection | SSH, HTTP, HTTPS |
Protocol | Usually TCP | TCP |
Port Range | Communication port | 22, 80, 443 |
Source/Destination | IP or Security Group |
0.0.0.0/0 (all) or your IP |
Example Rule:
Type | Protocol | Port | Source |
---|---|---|---|
SSH | TCP | 22 | Your IP (203.x.x.x/32 ) |
HTTP | TCP | 80 | 0.0.0.0/0 |
5. Key Characteristics
โ You can attach:
- One SG โ multiple instances
- One instance โ multiple SGs
โ SGs are:
- Region-specific
- VPC-specific
โ SGs live outside the instance (so blocked traffic never reaches it).
โ
If your app times out, itโs probably an SG issue.
If you get connection refused, SG worked but the app isnโt running.
6. Best Practices
- Create a dedicated SG for SSH (port 22) and restrict it to your IP only.
Example:
MySSH-SG
โ Inbound rule: SSH (22) โ Source: your IP. - Create separate SGs for each application/service (e.g., web, database).
- Regularly review inbound rules โ remove unused ones.
7. Referencing Other Security Groups
Security groups can reference other security groups instead of IPs.
Why use it?
When instances must communicate internally (e.g., web server โ database),
you donโt have to manage IP addresses.
Example:
- SG-Web โ allows inbound HTTP (80) from
0.0.0.0/0
- SG-DB โ allows inbound MySQL (3306) from SG-Web
โก๏ธ Any instance with SG-Web can talk to instances with SG-DB over port 3306.
This is common with load balancers and multi-tier apps.
8. Common Ports to Remember
Port | Protocol | Purpose |
---|---|---|
22 | SSH | Linux remote login |
21 | FTP | File Transfer Protocol |
22 | SFTP | Secure File Transfer (uses SSH) |
80 | HTTP | Unsecured web traffic |
443 | HTTPS | Secured web traffic |
3389 | RDP | Remote Desktop (Windows) |
9. Quick Recap
โ
Inbound = Blocked by default
โ
Outbound = Allowed by default
โ
Security Groups = ALLOW rules only
โ
Region + VPC bound
โ
Timeout โ SG issue, Connection Refused โ App issue
๐ Hands-On: Working with Security Groups in EC2
1. Where to Find Security Groups
- In the EC2 Console, select your instance โ click Security tab.
-
Youโll see:
- Inbound rules
- Outbound rules
- Linked Security Group(s)
For a full view:
๐ Left menu โ Network & Security โ Security Groups
2. Default Security Groups
Youโll typically see:
- Default security group (created automatically per VPC)
- Launch-wizard-1 (created during your first EC2 launch)
Each SG has:
- A unique ID (e.g.,
sg-0a12b3c4d5e6f
) - Inbound rules โ traffic into your instance
- Outbound rules โ traffic out of your instance
3. Viewing and Editing Inbound Rules
Example: Launch-wizard-1
Type | Protocol | Port | Source | Purpose |
---|---|---|---|---|
SSH | TCP | 22 | 0.0.0.0/0 | Remote terminal access |
HTTP | TCP | 80 | 0.0.0.0/0 | Web server access |
-
These rules allowed us to:
- SSH into the instance (port 22)
-
Access the web page (
http://<Public-IP>
) on port 80
4. Testing Firewall Behavior
๐ธ Case 1 โ Remove the HTTP rule
- Delete the inbound rule for port 80.
- Save changes.
- Try reloading your website โ โ Timeout
๐ง Timeout = Security Group issue
- Your request never reached the EC2 instance.
- Fix: check inbound rules.
๐ธ Case 2 โ Add the HTTP rule back
-
Add inbound rule:
- Type: HTTP
- Port: 80
-
Source: Anywhere (
0.0.0.0/0
)
Save rules โ โ Refresh your page โ Works again!
The port 80 rule allows public HTTP access to your web server.
5. Adding New Rules
You can:
- Choose any port or port range (e.g., 443 for HTTPS).
- Pick from the dropdown list (common protocols).
-
Specify source:
-
Anywhere
(0.0.0.0/0
) โ open to everyone -
My IP
โ restrict access to your own machine - Custom CIDR, security group, or prefix list โ for advanced setups
-
โ ๏ธ Note: If your IP changes (e.g., new Wi-Fi or VPN), youโll lose access if rule is โMy IPโ.
6. Outbound Rules
Default outbound rule:
Type | Protocol | Port | Destination |
---|---|---|---|
All traffic | All | All | 0.0.0.0/0 |
โ This allows your instance to download updates, connect to APIs, or reach the internet freely.
7. Multiple Security Groups and Instances
- One EC2 instance can have multiple SGs attached.
- One SG can be attached to multiple EC2 instances.
- Combined rules are additive โ all allowed traffic from each SG is permitted.
8. Quick Diagnostic Tip
Symptom | Meaning | Fix |
---|---|---|
โ Timeout | Blocked by SG (no inbound rule) | Add correct inbound rule |
โ ๏ธ Connection Refused | App/service not running on port | Start service inside EC2 |
โ Summary
- SGs control inbound and outbound traffic.
- Theyโre stateful โ return traffic is automatically allowed.
- Timeouts = SG misconfiguration, not instance failure.
- Use least privilege โ only open required ports.
- One SG = many instances; one instance = many SGs.
๐งฉ Connecting to Your EC2 Instance
1. Why We Need It
After launching an EC2 instance, the next step is to connect inside the server โ
to install software, check logs, or perform maintenance.
To do this securely, AWS provides several connection methods, depending on your computerโs operating system.
2. The SSH Protocol
๐ What is SSH?
SSH (Secure Shell) is a protocol that allows secure, encrypted remote access to Linux servers.
It lets you:
- Run commands directly on your EC2 instance.
- Manage software, configurations, and troubleshooting.
- Transfer files securely (via SFTP or SCP).
3. Methods by Operating System
Platform | Recommended Method | Tool | Notes |
---|---|---|---|
Mac / Linux | SSH command-line | Built-in terminal | Use ssh -i your-key.pem ec2-user@<Public-IP>
|
Windows 10 / 11 | SSH (built-in PowerShell) | Use ssh command |
Works the same as on Mac/Linux |
Windows 7 / 8 (or older) | PuTTY | Separate application | Convert .pem โ .ppk file first |
Any OS (browser-based) | EC2 Instance Connect | AWS Console โ โConnectโ โ โEC2 Instance Connectโ | Easiest, no software setup |
4. ๐ง EC2 Instance Connect (Recommended for Beginners)
โ Advantages:
- Works on Mac, Linux, Windows โ any browser.
- No setup, no key conversion, no CLI required.
- Uses your AWS credentials securely.
- Best for quick testing and short sessions.
โ ๏ธ Limitation:
- Currently supports Amazon Linux 2 and Ubuntu instances only.
- Not ideal for automation or long-term maintenance.
5. โ๏ธ When to Use SSH
- For advanced work, scripting, or automation.
- When using custom Linux distributions.
- When setting up multiple servers with consistent access.
Example SSH Command (Mac/Linux/Win10+)
ssh -i ~/Downloads/ec2tutorial.pem ec2-user@<Public-IP>
Replace
<Public-IP>
with your instanceโs address.
Ensure port 22 is open in your Security Group.
6. Common SSH Connection Issues
Problem | Likely Cause | Fix |
---|---|---|
โ Timeout | Security Group missing port 22 rule | Add inbound rule for SSH (port 22, your IP) |
โ ๏ธ Permission denied (publickey) | Wrong key or wrong user name | Use correct .pem and correct user (ec2-user for Amazon Linux) |
โ๏ธ Connection refused | Instance not running or booting | Wait for โRunningโ state |
๐ Wrong IP | Instance stopped/restarted | Use new Public IP or attach an Elastic IP |
7. ๐ก Instructor Tips
- Only one method needs to work (SSH or EC2 Instance Connect).
- Donโt stress if SSH fails โ youโll still progress fine with EC2 Instance Connect.
- Keep your
.pem
key safe โ AWS doesnโt allow redownloads. - Always check Security Group rules before troubleshooting deeper.
8. ๐งญ Next Steps
- Identify your OS.
- Use the right connection method:
- Mac/Linux โ SSH
- Windows 10+ โ PowerShell SSH
- Windows 7/8 โ PuTTY
- Any OS โ EC2 Instance Connect
- Connect and explore your EC2 server.
๐ป Connecting to EC2 with SSH (Mac or Linux)
1. ๐ฏ Goal
Use SSH (Secure Shell) to remotely access your EC2 instance from your local terminal.
Once connected, youโll be able to:
- Run Linux commands directly on the EC2 machine
- Verify network connectivity
- Manage and troubleshoot your cloud server
2. ๐งฑ How SSH Works
Diagram:
Your Laptop (SSH Client)
โ Port 22 (SSH)
Internet
โ
EC2 Instance (Amazon Linux 2)
Security Group โ allows Port 22 inbound
Explanation:
- SSH uses Port 22 to securely connect to the server.
- The Security Group must allow inbound access on Port 22.
- The connection authenticates using your private key (.pem).
3. ๐งฉ Preparation Steps
- Locate your downloaded key file (e.g.
EC2Tutorial.pem
).
-
Rename it to remove spaces โ โ
EC2Tutorial.pem
- Move it to a safe folder (e.g.
~/aws-course/
). - In AWS Console:
- Move it to a safe folder (e.g.
Go to EC2 โ Instances
Copy your Public IPv4 Address
-
Check Security Group โ must allow:
Type: SSH | Protocol: TCP | Port: 22 | Source: 0.0.0.0/0
4. ๐ฅ๏ธ Navigate to the Key File
Open your terminal:
cd ~/aws-course
ls
You should see:
EC2Tutorial.pem
If not:
- Use
pwd
to see where you are. - Use
cd ..
to go up a directory until you find your folder.
5. ๐ Set Proper Permissions
Your key file must not be publicly viewable:
chmod 400 EC2Tutorial.pem
This means: only you can read the file.
6. ๐ Connect via SSH
Run:
ssh -i EC2Tutorial.pem ec2-user@<Public-IP>
Example:
ssh -i EC2Tutorial.pem ec2-user@54.165.90.11
-
-i
โ specify your private key file -
ec2-user
โ default username for Amazon Linux 2 -
<Public-IP>
โ your EC2โs public IPv4 address
If prompted with:
Are you sure you want to continue connecting (yes/no)?
โ type yes.
7. โ Youโre In!
If successful, your prompt changes:
[ec2-user@ip-172-31-45-20 ~]$
Youโre now inside your EC2 instance.
8. ๐งช Try Basic Commands
whoami # shows current user (ec2-user)
hostname # displays machine name
ping google.com
Press Ctrl + C to stop the ping.
9. ๐ช Exit the SSH Session
To disconnect:
exit
or press Ctrl + D.
10. โ ๏ธ Important Notes
- If you stop and start your instance โ the Public IP changes. Update your SSH command accordingly.
- Keep your
.pem
file secure โ you cannot re-download it from AWS. -
If you see "Permission denied", check:
- File permissions (
chmod 400
) - Username (
ec2-user
) - Correct IP address
- Port 22 open in security group
- File permissions (
๐ง Summary
Step | Command | Purpose |
---|---|---|
1 | chmod 400 EC2Tutorial.pem |
Secure key permissions |
2 | ssh -i EC2Tutorial.pem ec2-user@<Public-IP> |
Connect to instance |
3 |
whoami / ping google.com
|
Test access |
4 | exit |
Disconnect safely |
๐ป Connecting to EC2 Using SSH on Windows (PuTTY Method)
1. ๐ฏ Goal
Learn how to connect (SSH) from a Windows computer to an Amazon Linux 2 EC2 instance using PuTTY.
SSH lets you:
- Control your EC2 instance remotely from Windows.
- Run commands directly on your cloud server.
- Troubleshoot or configure your Linux machine securely.
2. ๐ How It Works
Your Windows PC (PuTTY)
โ Port 22 (SSH)
Internet
โ
EC2 Instance (Amazon Linux 2)
Security Group โ allows Port 22 inbound
โ
SSH (Secure Shell) runs over Port 22
โ
The EC2 Security Group must allow:
Type: SSH
Protocol: TCP
Port: 22
Source: 0.0.0.0/0
3. ๐งฉ Prerequisites
- You already launched an EC2 instance (Amazon Linux 2).
- You downloaded your key pair file (e.g.,
EC2Tutorial.pem
). - You are using Windows 7, 8, or older (PuTTY required).
For Windows 10+, you can use PowerShell SSH instead.
4. ๐งฐ Install PuTTY Tools
Go to https://www.putty.org/
Download and install:
- PuTTY (main SSH app)
- PuTTYgen (key converter tool)
During setup โ click Next โ Install โ Finish โ
5. ๐ Convert Your .PEM Key to .PPK
PuTTY requires .ppk
format for private keys.
Steps:
- Open PuTTYgen.
- Click Load.
- Navigate to your
.pem
file (e.g.,EC2Tutorial.pem
).
- If itโs not visible โ choose All Files (.) at the bottom right.
- Select the file โ click Open.
- Youโll see:
"Successfully imported foreign key"
- Click Save private key โ choose a name like
EC2Tutorial.ppk
. - When asked about a passphrase โ click Yes (no passphrase needed).
- Save it (e.g., on your Desktop).
โ
You now have both:
EC2Tutorial.pem (AWS original)
EC2Tutorial.ppk (PuTTY-compatible)
6. โ๏ธ Configure PuTTY to Connect
Open PuTTY.
In Host Name (or IP address), enter:
ec2-user@<Public-IP>
Example:
ec2-user@54.167.123.45
Port: 22
Connection type: SSHIn the Category list โ expand SSH โ click Auth.
Under โPrivate key file for authenticationโ โ click Browse.
Select your
.ppk
file (e.g.,EC2Tutorial.ppk
).Go back to Session (top of the list).
Under โSaved Sessions,โ name it something like:
EC2-Instance
Then click Save.
โ This stores your connection and key configuration.
7. ๐ Connect to EC2
- Select your saved session (
EC2-Instance
). - Click Open.
- A security alert appears:
โThe serverโs host key is not cached in the registry.โ
โ Click Yes (to trust it).
- Youโll see:
login as:
Type:
ec2-user
- โ Youโre in your EC2 instance!
8. ๐งช Test Commands
Inside PuTTY, try:
whoami # shows current user
hostname # shows machine name
ping google.com # tests internet connectivity
To stop the ping โ Ctrl + C.
9. ๐ช Exit and Reconnect
- To leave the session:
exit
-
Next time:
- Open PuTTY
- Load your saved session (
EC2-Instance
) - Click Open
- Youโll be logged in instantly โ no need to reconfigure.
10. โ ๏ธ Common Troubleshooting
Problem | Likely Cause | Fix |
---|---|---|
โ Timeout | Missing SSH rule in Security Group | Add inbound rule for port 22 |
โ ๏ธ No auth methods available | Didnโt attach the .ppk key |
Re-add the private key under SSH โ Auth |
โ๏ธ Permission denied (publickey) | Wrong username | Use ec2-user (not root) |
๐ Connection refused | Instance not running or wrong IP | Start instance and use new Public IP |
๐ง Key Takeaways
- PuTTY is the SSH tool for Windows 7/8.
- Always convert
.pem
โ.ppk
using PuTTYgen. - Use
ec2-user
as the default login for Amazon Linux 2. - Always check port 22 is open in your Security Group.
- Save your session โ it saves time for future logins.
๐ป Connecting to EC2 Using SSH on Windows 10 (PowerShell)
1. ๐ฏ Goal
Learn to connect (SSH) from a Windows 10 or later machine directly to your EC2 instance โ without PuTTY โ using PowerShell or Command Prompt.
2. ๐ What Is SSH?
SSH (Secure Shell) lets you:
- Remotely control your EC2 Linux server through a command line.
- Run, install, or troubleshoot applications securely.
- Avoid using any GUI โ all actions happen via text commands.
3. ๐ How It Works
Your Windows 10 PC (PowerShell SSH)
โ Port 22 (SSH)
Internet
โ
EC2 Instance (Amazon Linux 2)
Security Group โ allows Port 22 inbound
โ
Port 22 must be open in the Security Group:
Type: SSH | Protocol: TCP | Port Range: 22 | Source: 0.0.0.0/0
4. ๐งฉ Check If SSH Is Available
Open PowerShell or Command Prompt and type:
ssh
- If you see command help (e.g. usage options) โ SSH is installed. โ
- If not โ install the Windows โOpenSSH Clientโ feature or use PuTTY (see previous lecture).
5. ๐ Locate Your Key File
Your key file is the .pem
file you downloaded from AWS (e.g. EC2Tutorial.pem
).
Steps:
- Place it somewhere simple โ e.g.
Desktop
orC:\Users\<YourName>\aws-course
- In PowerShell:
cd .\Desktop
ls
You should see your .pem
file listed.
6. โ๏ธ Connect Using SSH
The command format is:
ssh -i "EC2Tutorial.pem" ec2-user@<Public-IP>
Example:
ssh -i "EC2Tutorial.pem" ec2-user@3.94.152.11
Explanation:
Part | Meaning |
---|---|
-i |
Path to your private key (.pem file) |
ec2-user |
Default Linux username for Amazon Linux 2 |
@<Public-IP> |
The public IPv4 address of your EC2 instance |
7. โ ๏ธ First-Time Connection
Youโll see:
The authenticity of host ... can't be established.
Are you sure you want to continue connecting (yes/no)?
โ Type yes
โ
You are now inside your EC2 instance!
8. ๐งฐ If You Get Permission Errors
Windows sometimes restricts .pem
file permissions, causing:
Permissions for 'EC2Tutorial.pem' are too open.
Fixing Permissions:
- Right-click your
.pem
file โ Properties - Go to Security tab โ Advanced
- Make sure:
- Owner = your Windows user account
-
Click Change if needed โ type your username โ Check Names โ OK
- Click Disable inheritance โ select Remove all inherited permissions
- Click Add โ Select a principal
Type your username โ Check Names โ OK
-
Give yourself Full control
- Apply and close all dialogs.
โ Now only you (the owner) have access to the key โ SSH will work without warnings.
9. ๐งช Verify Connection
Once connected, try:
whoami # shows the current user
hostname # shows the EC2 machine name
ping google.com # tests internet connectivity
Press Ctrl + C to stop the ping.
10. ๐ช Exit the Session
To disconnect:
exit
or press Ctrl + D.
11. ๐ง Key Tips
Action | Command/Note |
---|---|
Check SSH installed |
ssh in PowerShell or CMD |
Navigate to key location | cd .\Desktop |
Connect | ssh -i EC2Tutorial.pem ec2-user@<Public-IP> |
Fix permissions | Change file owner + disable inheritance |
Exit |
exit or Ctrl + D
|
Public IP changes | If you stop/start EC2 โ use new IP address |
โ Summary
- Windows 10+ has built-in SSH โ no need for PuTTY.
- Use your .pem key from AWS to authenticate.
- Adjust file permissions if Windows blocks access.
- Always ensure port 22 is open in your Security Group.
๐ Connecting to EC2 Using EC2 Instance Connect (Browser-Based SSH)
1. ๐ฏ Goal
Learn to connect to your Amazon EC2 instance directly from the AWS Console โ
without needing any .pem
key, PuTTY, or terminal setup.
This method works on Windows, Mac, and Linux using only a web browser.
2. โ๏ธ What Is EC2 Instance Connect?
EC2 Instance Connect is a browser-based SSH client built into AWS.
It:
- Lets you open a secure terminal session in your browser.
- Uses a temporary SSH key (uploaded automatically by AWS).
- Requires no manual key management.
- Works with Amazon Linux 2 and Ubuntu instances.
3. ๐งฑ How It Works
Browser (AWS Console)
โ HTTPS (Port 443)
AWS EC2 Instance Connect Service
โ Temporary SSH key (Port 22)
EC2 Instance (Amazon Linux 2)
Security Group โ must allow inbound port 22
โ
Behind the scenes, it still uses SSH โ
so port 22 must be open in your Security Group.
4. ๐ Step-by-Step: Connecting
- Go to EC2 Console โ Instances
- Select your instance (e.g.
My First Instance
) - Click Connect (top right)
- Choose EC2 Instance Connect (browser-based SSH)
- Confirm details:
- Instance ID: prefilled
- Public IPv4 address: visible
-
Username:
ec2-user
(default for Amazon Linux 2)- Click Connect
โ Within seconds, a new browser tab opens โ you are now inside your EC2 instance terminal!
5. ๐งช Try Some Commands
In the browser terminal:
whoami # shows 'ec2-user'
hostname # shows internal hostname
ping google.com # test connectivity
Press Ctrl + C to stop the ping.
6. ๐ Troubleshooting EC2 Instance Connect
โ Connection Error:
โThere was a problem connecting to your instanceโ
โ Fix: Ensure Port 22 Is Open
- Go to EC2 โ Security Groups
- Select the group attached to your instance.
- Click Edit inbound rules
- Add:
Type: SSH | Protocol: TCP | Port Range: 22 | Source: 0.0.0.0/0
- (Optional) Add IPv6 rule if needed:
Type: SSH | Protocol: TCP | Port Range: 22 | Source: ::/0
- Save changes โ try connecting again.
7. ๐ง Key Points to Remember
- EC2 Instance Connect is quickest for beginners โ no setup, no key downloads.
- It still relies on SSH port 22 โ inbound rules must allow access.
- It uses temporary credentials valid only for the session.
- If you remove the SSH rule โ connection fails immediately.
- Works best for short admin sessions or training labs.
8. โ Summary
Feature | EC2 Instance Connect |
---|---|
Setup required | None (browser only) |
SSH key needed | Temporary key handled by AWS |
Port required | 22 (SSH) |
Supported OS | Amazon Linux 2, Ubuntu |
Security | Uses HTTPS + ephemeral SSH key |
Best for | Quick access, demos, and student labs |
๐ Using IAM Roles with EC2 Instances
1. ๐ฏ Goal
Learn how to securely give your EC2 instance permission to access AWS services using IAM Roles โ
without storing Access Keys or running aws configure
.
2. ๐ก Why IAM Roles?
In AWS, EC2 instances often need to access other services (like S3, DynamoDB, or IAM).
You could use AWS credentials (Access Key
+ Secret Key
) โ but thatโs unsafe.
โ Bad Practice:
Running:
aws configure
and entering your personal IAM user credentials exposes them to anyone with instance access.
They could retrieve keys and use them elsewhere โ a major security risk.
โ Correct Practice:
Use an IAM Role attached to the EC2 instance.
AWS automatically injects temporary credentials through the instance metadata service.
3. โ๏ธ How It Works
EC2 Instance
โ
IAM Role attached
โ
AWS automatically provides temporary credentials
โ
Access to AWS services (like IAM, S3, DynamoDB)
โ No keys stored
โ Rotates automatically
โ Least privilege by policy
4. ๐งช Hands-On: Attach an IAM Role to EC2
Step 1: Connect to EC2
Use EC2 Instance Connect or SSH โ both open a terminal inside your EC2.
In the shell, verify connection:
whoami
ping google.com
Then clear the screen:
clear
Step 2: Test AWS CLI Access
Try:
aws iam list-users
Youโll see:
Unable to locate credentials. You can configure credentials by running "aws configure".
This confirms your instance currently has no permissions.
Step 3: Create an IAM Role (if not already)
In AWS Console โ IAM โ Roles โ Create role
- Trusted entity: AWS Service
- Use case: EC2
- Attach permissions policy:
- Choose
IAMReadOnlyAccess
(for demo)-
Name:
DemoRoleForEC2
- Create role
-
Name:
Step 4: Attach Role to Instance
In AWS Console:
- Go to EC2 โ Instances
- Select your instance โ Actions โ Security โ Modify IAM Role
- From the dropdown, choose DemoRoleForEC2
- Click Save
Now go to the Security tab of your instance โ
youโll see:
IAM Role: DemoRoleForEC2
Step 5: Test Again
Back in the terminal:
aws iam list-users
โ
You now get a proper IAM response:
{
"Users": [
{
"UserName": "AdminUser",
"Arn": "arn:aws:iam::123456789012:user/AdminUser",
...
}
]
}
Step 6: Remove and Re-Test
Detach the policy from your IAM role (in IAM console โ Role โ Permissions โ Detach policy).
Then rerun:
aws iam list-users
โ Now you get:
An error occurred (AccessDenied) when calling the ListUsers operation: User is not authorized to perform iam:ListUsers
โ This proves that permissions are directly controlled by the IAM Role.
5. ๐ How the Role Credentials Work
You can check the temporary credentials with:
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/
This returns your IAM role name and a short-lived credential set.
AWS automatically rotates these keys for you.
6. ๐ง Key Takeaways
Concept | Explanation |
---|---|
IAM Role | Securely grants permissions to EC2 without credentials |
Policy | Defines what actions EC2 can perform |
AWS CLI | Automatically uses temporary role credentials |
Never use aws configure
|
Donโt hardcode keys on EC2 |
IAMReadOnlyAccess | Safe policy to view IAM data |
Metadata service | Provides auto-rotated credentials to EC2 |
โ Summary
- Never use static IAM keys inside EC2.
- Always attach an IAM Role to the instance.
- The role defines what AWS actions the instance can perform.
- IAM credentials are automatically provided and rotated by AWS.
- Use
aws cli
commands directly โ no configuration needed.
๐ฐ EC2 Instance Purchasing Options
1. ๐ฏ Goal
Understand how AWS offers different pricing models for EC2 โ
each optimized for cost, flexibility, or stability โ depending on workload type.
2. โ๏ธ Overview
AWS gives you six main purchasing options for EC2 instances:
Type | Duration | Best For | Discount (vs On-Demand) | Reliability |
---|---|---|---|---|
On-Demand | Pay-as-you-go | Short, unpredictable workloads | โ | โญโญโญโญโญ |
Reserved Instances (RI) | 1 or 3 years | Predictable, long-term workloads | Up to 72% | โญโญโญโญโญ |
Savings Plans | 1 or 3 years | Long-term spend commitment (flexible usage) | Up to 72% | โญโญโญโญโญ |
Spot Instances | Variable | Short, flexible, fault-tolerant tasks | Up to 90% | โญโญ |
Dedicated Hosts / Instances | Long-term | Compliance, licensing, or isolation needs | โ / Up to 70% | โญโญโญโญโญ |
Capacity Reservations | Flexible | Reserved AZ capacity without discount | 0% | โญโญโญโญ |
3. ๐งฉ 1๏ธโฃ On-Demand Instances
- Pay per second (Linux/Windows) or per hour (other OS).
- No upfront cost, no commitment.
- Highest flexibility, highest price.
-
Perfect for:
- Testing, proof of concept, dev environments.
- Unpredictable workloads.
๐ก Example:
โRun when you want, stop when you want โ like renting a car by the hour.โ
4. ๐ก 2๏ธโฃ Reserved Instances (RI)
- Commit for 1 or 3 years.
- Save up to 72% compared to On-Demand.
- Fixed attributes: instance type, region, tenancy, OS.
-
Payment options:
- No upfront
- Partial upfront
- All upfront (max discount)
-
Two types:
- Standard RI โ fixed configuration
- Convertible RI โ change family, OS, or size (discount ~66%)
Can buy/sell on AWS RI Marketplace.
โ
Use for:
Steady workloads like databases, web servers, or ERP systems.
5. ๐ธ 3๏ธโฃ Savings Plans
- Modern alternative to RI.
- Commit to spend a fixed $/hour (e.g., $10/hour for 3 years).
- AWS automatically applies discount to matching compute usage.
-
Flexibility:
- Any instance size in same family.
- Switch between Linux โ Windows.
- Works with EC2, Fargate, Lambda.
โ
Use for:
Dynamic environments where workload changes but total spend is predictable.
๐ก Analogy:
โYou commit to spending $300 per month at a hotel โ you can change rooms anytime.โ
6. โก 4๏ธโฃ Spot Instances
- Up to 90% cheaper than On-Demand.
- AWS reclaims instances anytime with a 2-minute warning.
-
Ideal for workloads tolerant to interruptions:
- Batch jobs, rendering, data analysis, CI/CD runners, machine learning training.
-
Not suited for:
- Databases or critical systems.
๐ก Analogy:
โLike last-minute hotel deals โ super cheap, but you might get kicked out anytime.โ
7. ๐ 5๏ธโฃ Dedicated Hosts & Dedicated Instances
Dedicated Host
- Physical server fully reserved for your account.
- Visibility into underlying sockets, cores, VMs.
-
Use for:
- Bring Your Own License (BYOL) software (Oracle, SQL Server, etc.).
- Compliance or regulatory isolation needs.
Billed per host, can be reserved 1 or 3 years.
Dedicated Instance
- Runs on hardware dedicated to you, but AWS manages placement.
- You donโt see or control the physical server.
- Slightly cheaper than Dedicated Host.
๐ก Difference:
Feature | Dedicated Instance | Dedicated Host |
---|---|---|
Control over placement | โ | โ |
Hardware visibility | โ | โ |
Licensing (BYOL) support | โ | โ |
Cost | Lower | Higher |
8. ๐งฑ 6๏ธโฃ Capacity Reservations
- Reserve capacity in a specific Availability Zone (AZ).
- No discount โ billed at On-Demand rate.
- Guarantees instance availability even during high demand.
- Can be canceled anytime.
โ Use for:
- Mission-critical workloads that must always launch.
- Short-term events or DR (disaster recovery) readiness.
๐ก Analogy:
โYou book a hotel room but pay even if you donโt stay โ youโre guaranteed itโs there.โ
9. ๐งฎ Cost & Use Case Comparison
Option | Duration | Commitment | Discount | Suitable For | Risk of Interruption |
---|---|---|---|---|---|
On-Demand | None | None | โ | Short, unpredictable workloads | โ |
Reserved Instance | 1โ3 yrs | Fixed | Up to 72% | Steady usage | โ |
Savings Plan | 1โ3 yrs | Spend commitment | Up to 72% | Flexible long-term | โ |
Spot Instance | None | Variable | Up to 90% | Short, interruptible | โ |
Dedicated Host | 1โ3 yrs | Fixed | โ | Compliance, BYOL | โ |
Capacity Reservation | Any | None | 0% | Guaranteed capacity | โ |
10. ๐จ Hotel Analogy (Easiest to Remember)
Option | Analogy | Description |
---|---|---|
On-Demand | Walk-in guest | Pay full price, come and go anytime |
Reserved Instance | Long-term resident | Pay less for committing to stay longer |
Savings Plan | Monthly membership | Spend fixed $ each month, flexible room type |
Spot Instance | Last-minute deal | Cheap, but may lose your room anytime |
Dedicated Host | Rent the whole hotel | Full control, private property |
Capacity Reservation | Reserve a room just in case | Pay even if you donโt use it |
11. ๐ง Exam & Interview Tips
- โOn-Demand โ short, unpredictable, no commitment.
- ๐กReserved Instance โ predictable workloads (DBs, web apps).
- ๐ฐSavings Plan โ flexible workloads, commit to spend.
- โ๏ธSpot โ batch, ML, non-critical compute.
- ๐งพDedicated Host โ compliance or BYOL licensing.
- ๐งฉCapacity Reservation โ guaranteed AZ availability.
โ Summary
Feature | Optimized For | Example |
---|---|---|
On-Demand | Flexibility | Dev/test, startups |
Reserved | Predictability | Databases |
Savings Plan | Spending control | Constant EC2 usage |
Spot | Cost savings | Batch, analytics |
Dedicated Host | Compliance & licenses | Oracle workloads |
Capacity Reservation | Availability guarantee | Disaster recovery |
โก Deep Dive: EC2 Spot Instances
1. ๐ฏ Goal
Learn how EC2 Spot Instances work, how to use them safely, and how AWS manages interruptions, pricing, and automation for massive cost savings.
2. ๐ฐ Why Spot Instances?
- Up to 90% cheaper than On-Demand.
- You use unused EC2 capacity that AWS sells at a discount.
- You must be prepared for interruptions.
โ Ideal for:
- Batch jobs
- CI/CD runners
- Data analytics
- ML training
- Image/video processing
- Container clusters (ECS, EKS)
โ Not ideal for:
- Databases
- Stateful apps
- Long-lived sessions
- Mission-critical production workloads
3. โ๏ธ How Spot Pricing Works
๐ธ Step 1 โ You define:
Max Spot Price = the most youโre willing to pay/hour
๐ธ Step 2 โ AWS publishes:
Current Spot Price (varies by instance type & AZ)
๐ธ Step 3 โ If:
Condition | Result |
---|---|
Spot price โค Max price | โ Instance runs |
Spot price > Max price | โ ๏ธ Instance interrupted (2-minute warning) |
4. โฐ Two-Minute Interruption Notice
When AWS reclaims your instance, you get a 2-minute warning.
You can:
- Stop the instance โ retain EBS data; restart later.
- Terminate the instance โ lose ephemeral data; cheaper.
๐ก Choose based on workload type:
- Stop โ stateful compute
- Terminate โ stateless batch jobs
5. ๐งฑ Spot Blocks (Fixed-Duration Instances)
- Lock a spot instance for 1โ6 hours.
- AWS guarantees no interruption during that period (except in rare capacity loss).
- Cost is higher than standard Spot, but still cheaper than On-Demand.
โ Best for predictable short jobs (e.g., nightly builds, simulations).
6. ๐ Spot Price Behavior
- Prices fluctuate by Availability Zone and instance family.
- Reflect supply and demand โ not user bidding anymore (AWS sets the price).
- Typically stable, but may spike if capacity tightens.
๐ก Example:
m4.large
On-Demand: $0.10/hr
Spot average: ~$0.04/hr โ 60%+ savings
7. ๐งฉ Spot Requests
A Spot Request defines:
- Number of instances
- Max price
- AMI, instance type, subnet
- Duration (valid from/until)
- Request type โ One-Time or Persistent
๐น One-Time Request
- Launches once โ fulfilled โ ends automatically.
- Good for single batch jobs.
๐น Persistent Request
- Stays open until canceled.
- If an instance is terminated due to price/capacity, AWS automatically relaunches new ones when conditions improve.
8. โ How to Cancel Spot Requests Properly
โ ๏ธ Order matters:
- Cancel the Spot Request โ Prevents AWS from launching replacements.
- Terminate the Spot Instances โ Frees resources youโre billed for.
If you terminate first (without canceling),
the Spot Request sees โ0 instances runningโ and relaunches them again.
โ Exam Tip โ Always cancel request first, then terminate instances.
9. ๐ Spot Fleets
A Spot Fleet = group of Spot + (optional) On-Demand instances that AWS manages to meet a target capacity at lowest possible cost.
๐ฆ What You Define
- Target capacity (e.g., 100 vCPUs or 10 instances)
-
Multiple launch pools:
- Different instance types
- Different AZs
- Different OSs
Allocation strategy (below)
โ๏ธ Allocation Strategies
Strategy | Description | Best For |
---|---|---|
Lowest-Price | Chooses the cheapest pool | Cost-optimized short workloads |
Diversified | Spreads across multiple pools | Availability-focused, long workloads |
Capacity-Optimized | Chooses pools with best capacity | Large-scale, reliable compute |
Price-Capacity-Optimized | Balances lowest price + available capacity | ๐น Best for most real workloads |
โ AWS automatically replaces lost instances to maintain capacity.
10. ๐ Spot Fleet vs Simple Spot Request
Feature | Spot Request | Spot Fleet |
---|---|---|
Single instance type | โ | โ |
Multiple instance types | โ | โ |
Across multiple AZs | โ | โ |
Includes On-Demand | โ | โ |
Auto-optimization | โ | โ |
Best for | Simple job | Cost-optimized scaling cluster |
๐ก Think of Spot Fleet as an intelligent manager that keeps your compute capacity running at the lowest possible cost.
11. ๐ก Practical Examples
Use Case | Best Approach |
---|---|
Hadoop/Spark batch jobs | Spot Fleet (diversified) |
CI/CD pipelines | Spot Block (1โ6 hrs) |
ML model training | Spot Fleet (price-capacity-optimized) |
Web servers with ASG | Combine On-Demand + Spot mix |
Databases | Never use Spot |
12. ๐ง Exam & Interview Tips
- Spot = cheapest but interruptible.
- 2-minute warning before termination.
- Spot Block = 1โ6 hr fixed duration.
- Cancel request โ then terminate instances.
- Spot Fleet optimizes across types, AZs, and prices.
- Price-Capacity-Optimized = best modern default.
- Donโt use Spot for critical or stateful systems.
โ Summary
Feature | Description |
---|---|
Max discount | Up to 90% |
Billing unit | Per second |
Interruption notice | 2 minutes |
Typical use cases | Batch, analytics, CI/CD |
Donโt use for | Databases, critical workloads |
Key services | Spot Request, Spot Fleet |
Recommended strategy | Price-Capacity-Optimized |
๐ All the Ways to Launch EC2 Instances
1. ๐ฏ Goal
Understand every method AWS offers to launch EC2 instances, from Spot Requests to Dedicated Hosts, and when each is appropriate for cost, flexibility, or compliance.
2. โก Option 1 โ Spot Requests
๐ฐ Save up to 90% on compute costs!
A Spot Request asks AWS for spare EC2 capacity at discounted pricing.
๐งญ Steps in the Console
- In the EC2 Dashboard, go to Spot Requests.
- Click Pricing history โ view past 3 months for any instance type (e.g.,
c4.large
).
- Black bar = On-Demand price.
- Colored lines = Spot prices per AZ.
- Typically 60โ70% cheaper and quite stable.
๐งฑ Create a Spot Request
Click Request Spot Instances โ You can either:
- Use a Launch Template, or
-
Manually configure launch settings:
- AMI (e.g., Amazon Linux 2)
- Key pair
- VPC/subnet
- Security group
โ๏ธ Request Details
Setting | Description |
---|---|
Max Price | Max hourly rate youโre willing to pay. If AWSโs Spot price rises above this, the instance is stopped or terminated. |
Valid From / Valid Until | Defines the active time window of your request. |
Terminate when expired | Decide whether to stop instances when request expires. |
Load Balancer/Target Group | (Optional) attach to ELB/ALB target group. |
๐ Target Capacity
- Define how many instances or vCPUs you want.
- Choose to maintain capacity โ AWS will automatically re-launch if any are lost.
- Interruption behavior:
terminate
,stop
, orhibernate
.
๐ Networking
- Choose VPC, subnet, and Availability Zone (AZ).
-
Pick instance types manually (e.g.,
c3.large
,c4.large
) or define attribute filters:- Min/max vCPUs
- Min/max memory
- Architecture, virtualization type, etc.
๐ก The broader your filters โ the more flexibility โ the cheaper AWS can provide capacity.
๐งฎ Allocation Strategy
Strategy | Description | Use Case |
---|---|---|
Lowest Price | Choose pools with lowest Spot price | Short workloads, max savings |
Capacity Optimized | Prefer pools with highest capacity | Large workloads |
Diversified | Spread across multiple pools | High availability |
Price-Capacity Optimized | Mix of cost + reliability | โ Recommended for most users |
You can also maintain a diverse pool of instance types for resilience.
๐งพ Example
Target capacity: 10 instances
Estimated fleet cost: $0.156/hr
Savings: ~73% vs On-Demand
3. โก Option 2 โ Launching Spot Instances Directly
Instead of Spot Fleet, you can launch directly from:
EC2 โ Instances โ Launch Instance โ Advanced details โ Request Spot Instances
Youโll see options:
-
Request type:
one-time
(default) orpersistent
- Max price: default = On-Demand price (can customize)
-
Interruption behavior:
stop
,terminate
,hibernate
- Request validity: specify start & end time
๐ก The โblock durationโ (1โ6 hour Spot blocks) feature was deprecated after Dec 2022.
4. ๐ธ Option 3 โ Reserved Instances (RI)
Buy capacity in advance for 1 or 3 years.
Console Flow:
- EC2 โ Reserved Instances
- Search instance type (e.g.,
c5.large
) - Choose:
- Term: 12 or 36 months
- Type: Standard or Convertible
- Payment: All Upfront / Partial / No Upfront
- Add to Cart โ View Cart โ (โ donโt actually purchase unless needed!)
๐ก Convertible RIs let you change instance family/OS.
Standard RIs are locked but cheaper.
โ ๏ธ Note: RIs are slowly being replaced by Savings Plans.
5. ๐ก Option 4 โ Savings Plans
A modern alternative to RIs, committing to spend a fixed $ per hour over 1โ3 years.
Features
-
Flexible across:
- Instance size
- OS
- Region
- Tenancy (default, dedicated, host)
Applies to EC2, Fargate, and Lambda usage.
Same savings as RIs (up to 72%).
โ Recommended for most long-term, steady workloads.
6. ๐ Option 5 โ Dedicated Hosts
Get a physical EC2 server fully reserved for your account.
Use Cases
- Compliance or regulatory isolation.
- BYOL (Bring Your Own License) software (Oracle, SQL Server).
- Control instance placement and underlying hardware.
Launch Steps
- EC2 โ Dedicated Hosts โ Allocate Dedicated Host
- Select:
- Instance family (e.g.,
c5
) - Availability Zone
- Click Allocate
โ ๏ธ Cost is much higher โ typically for enterprise or compliance workloads.
7. ๐งฑ Option 6 โ Capacity Reservations
Guarantee EC2 capacity in a specific Availability Zone (AZ) โ even if youโre not running anything yet.
Features
- Pay On-Demand price (no discount).
- Reserve exact instance type & count.
- Duration: open-ended or fixed end time.
- Cancelling stops future billing, but youโre charged while reserved.
โ Useful for:
- Disaster recovery (DR)
- Mission-critical systems
- Short-term but guaranteed compute bursts
Example:
Reserve 4 ร m5.2xlarge
in eu-central-1a
โ You pay even if not used, but AWS guarantees capacity exists.
8. ๐ง Comparison Summary
Option | Pricing | Commitment | Flexibility | Use Case |
---|---|---|---|---|
On-Demand | High | None | Very high | Unpredictable workloads |
Spot | Lowest | None | Moderate | Batch, analytics, non-critical |
Reserved | Low | 1โ3 yrs | Fixed | Databases, web servers |
Savings Plan | Low | 1โ3 yrs | High | Steady spend, variable workload |
Dedicated Host | Very high | Optional | Low | Licensing, compliance |
Capacity Reservation | On-Demand | None | Moderate | Guaranteed AZ capacity |
9. ๐ก Exam Tips
- Spot Instance: Interrupted โ 2-min warning.
- Spot Fleet: Combines pools for lowest cost.
- Reserved Instance: Locked to type + region.
- Convertible RI: Can change instance family.
- Savings Plan: Commit to spend $, flexible.
- Dedicated Host: Physical isolation.
- Capacity Reservation: Pay to reserve compute in an AZ.
- Spot Block: Deprecated after Dec 2022.
โ Summary
AWS provides six different launch paths for EC2:
- Spot Request / Fleet (lowest cost)
- Regular Launch โ request Spot Instance
- Reserved Instance
- Savings Plan
- Dedicated Host
- Capacity Reservation
Each one balances price, predictability, and flexibility differently.
Top comments (0)