AWS Pricing Models: Hands-On Exploration
AWS Pricing Models
AWS Pricing Models: Hands-On Exploration
Welcome to this guided lab on AWS Pricing Models. In this lab, we will translate the theoretical concepts of AWS compute pricing—specifically On-Demand and Spot Instances—into practical, hands-on experience.
Prerequisites
Before starting this lab, ensure you have the following ready:
- Active AWS Account: You need an AWS account with administrator or sufficient IAM permissions to create and terminate EC2 instances.
- AWS CLI Installed & Configured: The
awscommand-line interface must be installed and configured with your credentials (aws configure). - Existing Key Pair: An existing EC2 Key Pair in your chosen region to SSH into instances (optional but recommended).
- Basic AWS Knowledge: Familiarity with what an Amazon Elastic Compute Cloud (EC2) instance is.
Learning Objectives
By the end of this lab, you will be able to:
- Launch an On-Demand Instance and identify where pay-as-you-go pricing applies.
- Request a Spot Instance to take advantage of unused capacity at steep discounts.
- Evaluate pricing models using AWS cost management principles to choose the right model for specific workloads.
Here is a visual decision matrix to help you choose the right pricing model, which we will practice today:
Architecture Overview
In this lab, you will deploy two distinct EC2 instances using two different purchasing options within your default Virtual Private Cloud (VPC).
Step-by-Step Instructions
Step 1: Launch an On-Demand Instance
On-Demand is the default pricing model in AWS. You pay for compute capacity by the second with no long-term commitments. This is perfect for short-term, spiky, or unpredictable workloads (e.g., launching a brand-new e-commerce website where traffic is unknown).
# Define variables for your specific environment
AMI_ID="<YOUR_AMI_ID>"
KEY_NAME="<YOUR_KEY_PAIR>"
# Launch the On-Demand instance
aws ec2 run-instances \
--image-id $AMI_ID \
--count 1 \
--instance-type t2.micro \
--key-name $KEY_NAME \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=BrainyBee-OnDemand}]'[!TIP] You can find a valid Amazon Linux 2 AMI ID in the EC2 Console launch wizard. It typically starts with
ami-.
▶Console alternative
- Navigate to the EC2 Dashboard in the AWS Management Console.
- Click Launch Instance.
- Name the instance
BrainyBee-OnDemand. - Select Amazon Linux 2023 AMI.
- Keep the Instance type as t2.micro.
- Select your Key pair.
- Under Advanced Details, ensure "Purchasing option" is NOT checked for Spot instances. (On-Demand is default).
- Click Launch instance.
📸 Screenshot: Look for the green "Success" banner showing the Instance ID.
Step 2: Request a Spot Instance
Spot Instances allow you to bid on unused AWS compute capacity at discounts of up to 90% off the On-Demand price. However, AWS can reclaim this capacity with a two-minute warning. This is ideal for fault-tolerant workloads (e.g., a batch job processing images that can be restarted if interrupted).
# Request a one-time Spot instance
aws ec2 request-spot-instances \
--instance-count 1 \
--type "one-time" \
--launch-specification "{\"ImageId\":\"$AMI_ID\",\"InstanceType\":\"t2.micro\",\"KeyName\":\"$KEY_NAME\"}"▶Console alternative
- Navigate to the EC2 Dashboard.
- In the left-hand menu, under Instances, click Spot Requests.
- Click Request Spot Instances.
- Select Manually configure launch parameters.
- Choose the Amazon Linux AMI and t2.micro instance type.
- Review the pricing history and set your maximum price (or leave as default to match On-Demand).
- Click Create.
📸 Screenshot: The Spot Request dashboard showing your request state as "active" or "fulfilled".
Step 3: Tag Your Spot Instance (CLI Only)
Spot requests launch instances asynchronously. Once the Spot request is fulfilled, we need to tag the resulting instance so we can easily track it.
# 1. First, get the InstanceId from your Spot Request (Replace with your actual Spot Request ID)
SPOT_REQ_ID="<YOUR_SPOT_REQUEST_ID>"
aws ec2 describe-spot-instance-requests \
--spot-instance-request-ids $SPOT_REQ_ID \
--query 'SpotInstanceRequests[0].InstanceId' \
--output text
# 2. Tag the instance using the returned ID
aws ec2 create-tags \
--resources <RETURNED_INSTANCE_ID> \
--tags Key=Name,Value=BrainyBee-SpotCheckpoints
Let's verify that both of your instances are running successfully.
Run the following command to list all instances starting with the name BrainyBee:
aws ec2 describe-instances \
--filters "Name=tag:Name,Values=BrainyBee*" \
--query "Reservations[*].Instances[*].{ID:InstanceId,Name:Tags[0].Value,State:State.Name,Lifecycle:InstanceLifecycle}" \
--output tableExpected Output:
You should see a table with two instances. The On-Demand instance will have None or null for the Lifecycle column, while the Spot instance will explicitly show spot under the Lifecycle column.
| ID | Lifecycle | Name | State |
|---|---|---|---|
| i-0abcd1234 | None | BrainyBee-OnDemand | running |
| i-0efgh5678 | spot | BrainyBee-Spot | running |
Clean-Up / Teardown
[!WARNING] Cost Warning: Remember to run these teardown commands immediately after completing the lab. Even t2.micro instances will consume your Free Tier hours, and Spot instances will incur ongoing charges.
Terminate both instances and cancel the Spot request to avoid unwanted charges.
1. Terminate the On-Demand Instance:
# Replace with your On-Demand Instance ID
aws ec2 terminate-instances --instance-ids <YOUR_ONDEMAND_INSTANCE_ID>2. Cancel the Spot Request and Terminate the Spot Instance:
# Cancel the request
aws ec2 cancel-spot-instance-requests --spot-instance-request-ids <YOUR_SPOT_REQUEST_ID>
# Terminate the instance spawned by the request
aws ec2 terminate-instances --instance-ids <YOUR_SPOT_INSTANCE_ID>▶Console alternative
- Go to EC2 > Instances.
- Select both
BrainyBee-OnDemandandBrainyBee-Spotinstances. - Click Instance state > Terminate instance.
- Go to EC2 > Spot Requests.
- Select your Spot request, click Actions > Cancel request.
Troubleshooting
| Error / Issue | Probable Cause | Fix |
|---|---|---|
AuthFailure | AWS CLI is not configured properly or credentials expired. | Run aws configure and verify your Access Key and Secret Key. |
InvalidAMIID.NotFound | The AMI ID used does not exist in your current AWS Region. | Find a valid AMI ID for your specific region (e.g., us-east-1) via the console and update the variable. |
Spot Request stays open | There is no available spot capacity for t2.micro at your specified price. | Cancel the request and try a different instance type (e.g., t3.micro) or change your Availability Zone. |
MaxSpotInstanceCountExceeded | Your AWS account is new and has a restriction on Spot instances. | Use the AWS Support Center to request a limit increase for Spot Instances. |