Hands-On Lab863 words

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 aws command-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:

  1. Launch an On-Demand Instance and identify where pay-as-you-go pricing applies.
  2. Request a Spot Instance to take advantage of unused capacity at steep discounts.
  3. 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:

Loading Diagram...

Architecture Overview

In this lab, you will deploy two distinct EC2 instances using two different purchasing options within your default Virtual Private Cloud (VPC).

Loading Diagram...

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).

bash
# 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
  1. Navigate to the EC2 Dashboard in the AWS Management Console.
  2. Click Launch Instance.
  3. Name the instance BrainyBee-OnDemand.
  4. Select Amazon Linux 2023 AMI.
  5. Keep the Instance type as t2.micro.
  6. Select your Key pair.
  7. Under Advanced Details, ensure "Purchasing option" is NOT checked for Spot instances. (On-Demand is default).
  8. 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).

bash
# 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
  1. Navigate to the EC2 Dashboard.
  2. In the left-hand menu, under Instances, click Spot Requests.
  3. Click Request Spot Instances.
  4. Select Manually configure launch parameters.
  5. Choose the Amazon Linux AMI and t2.micro instance type.
  6. Review the pricing history and set your maximum price (or leave as default to match On-Demand).
  7. 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.

bash
# 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-Spot

Checkpoints

Let's verify that both of your instances are running successfully.

Run the following command to list all instances starting with the name BrainyBee:

bash
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 table

Expected 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.

IDLifecycleNameState
i-0abcd1234NoneBrainyBee-OnDemandrunning
i-0efgh5678spotBrainyBee-Spotrunning

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:

bash
# 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:

bash
# 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
  1. Go to EC2 > Instances.
  2. Select both BrainyBee-OnDemand and BrainyBee-Spot instances.
  3. Click Instance state > Terminate instance.
  4. Go to EC2 > Spot Requests.
  5. Select your Spot request, click Actions > Cancel request.

Troubleshooting

Error / IssueProbable CauseFix
AuthFailureAWS CLI is not configured properly or credentials expired.Run aws configure and verify your Access Key and Secret Key.
InvalidAMIID.NotFoundThe 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 openThere 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.
MaxSpotInstanceCountExceededYour AWS account is new and has a restriction on Spot instances.Use the AWS Support Center to request a limit increase for Spot Instances.

Ready to study AWS Certified Cloud Practitioner (CLF-C02)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free