Bird
Raised Fist0
AWScloud~10 mins

EC2 pricing models (on-demand, reserved, spot) in AWS - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the EC2 pricing model for an on-demand instance.

AWS
ec2_client.run_instances(InstanceType='t2.micro', MinCount=1, MaxCount=1, [1]={'MarketType':'on-demand'})
Drag options to blanks, or click blank then click option'
AInstanceMarketOptions
BMarketType
CInstanceLifecycle
DPricingModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'PricingModel' which is not a valid parameter.
Using 'InstanceLifecycle' which is not an input parameter for run_instances.
2fill in blank
medium

Complete the code to request a spot instance using the correct market option.

AWS
ec2_client.run_instances(InstanceType='t3.medium', MinCount=1, MaxCount=1, InstanceMarketOptions={'MarketType': [1])
Drag options to blanks, or click blank then click option'
A'on-demand'
B'reserved'
C'spot'
D'scheduled'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'reserved' or 'on-demand' which are different pricing models.
3fill in blank
hard

Fix the error in the code to correctly specify a reserved instance purchase option.

AWS
ec2_client.purchase_reserved_instances_offering(ReservedInstancesOfferingId='abc123', [1]=1)
Drag options to blanks, or click blank then click option'
AQuantity
BInstanceNumber
CCount
DInstanceCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Count' or 'InstanceCount' which are invalid for this API call.
4fill in blank
hard

Fill both blanks to configure a spot instance with a maximum price and interruption behavior.

AWS
ec2_client.run_instances(InstanceType='t3.large', MinCount=1, MaxCount=1, InstanceMarketOptions={'MarketType':'spot', 'SpotOptions':{'MaxPrice': [1], '[2]':'terminate'}})
Drag options to blanks, or click blank then click option'
A'0.05'
B'MaxPrice'
C'InstanceInterruptionBehavior'
D'0.5'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numeric types instead of strings for MaxPrice.
Confusing 'MaxPrice' with interruption behavior.
5fill in blank
hard

Fill all three blanks to create a dictionary that maps instance types to their pricing models.

AWS
pricing_map = [1](instance_type: [2] for instance_type, [3] in instances.items())
Drag options to blanks, or click blank then click option'
Adict
B'on-demand'
Cpricing_model
D'spot'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'spot' instead of 'on-demand' for the pricing model.
Using wrong variable names in the comprehension.

Practice

(1/5)
1. Which EC2 pricing model allows you to pay only for the compute time you use without any long-term commitment?
easy
A. Dedicated hosts
B. Reserved instances
C. Spot instances
D. On-demand instances

Solution

  1. Step 1: Understand On-demand pricing

    On-demand instances let you pay per hour or second without any upfront commitment.
  2. Step 2: Compare with other models

    Reserved requires commitment; Spot can be interrupted; Dedicated hosts are physical servers.
  3. Final Answer:

    On-demand instances -> Option D
  4. Quick Check:

    Pay-as-you-go = On-demand [OK]
Hint: No commitment means On-demand pricing [OK]
Common Mistakes:
  • Confusing Reserved with On-demand
  • Thinking Spot is always available
  • Mixing Dedicated hosts with pricing models
2. Which of the following is the correct way to describe Spot instances in AWS EC2?
easy
A. Instances with a fixed monthly fee
B. Instances that use spare capacity and can be interrupted
C. Instances reserved for 3 years with upfront payment
D. Instances that run only on dedicated hardware

Solution

  1. Step 1: Define Spot instances

    Spot instances use spare AWS capacity and are cheaper but can be stopped anytime.
  2. Step 2: Eliminate other options

    Fixed monthly fee applies to Reserved; dedicated hardware is Dedicated hosts.
  3. Final Answer:

    Instances that use spare capacity and can be interrupted -> Option B
  4. Quick Check:

    Spot = spare capacity + interruption [OK]
Hint: Spot = cheap but can stop anytime [OK]
Common Mistakes:
  • Thinking Spot has fixed fees
  • Confusing Reserved with Spot
  • Mixing Dedicated hosts with Spot
3. You launch an EC2 instance using Spot pricing. What happens if AWS needs the capacity back?
medium
A. Your instance is stopped or terminated with a 2-minute warning
B. You are charged the full On-demand price instead
C. Your instance continues running without interruption
D. Your instance is automatically converted to Reserved pricing

Solution

  1. Step 1: Understand Spot instance interruptions

    AWS can reclaim Spot instances anytime, giving a 2-minute warning before stopping or terminating.
  2. Step 2: Check other options

    Instances do not continue uninterrupted; no automatic price change or conversion to Reserved.
  3. Final Answer:

    Your instance is stopped or terminated with a 2-minute warning -> Option A
  4. Quick Check:

    Spot interruption = 2-minute warning stop [OK]
Hint: Spot instances get 2-minute stop warning [OK]
Common Mistakes:
  • Assuming Spot instances never stop
  • Thinking Spot switches to On-demand automatically
  • Believing Spot instances run like Reserved
4. A user wants to save costs by committing to a 1-year usage but accidentally selects On-demand pricing. What is the main issue with this choice?
medium
A. On-demand pricing does not offer cost savings for long-term commitment
B. On-demand pricing requires upfront payment for 1 year
C. On-demand pricing instances cannot be launched immediately
D. On-demand pricing instances are always interrupted

Solution

  1. Step 1: Understand On-demand pricing characteristics

    On-demand pricing charges per use with no upfront or commitment discounts.
  2. Step 2: Identify the cost-saving option

    Reserved instances offer savings with 1 or 3 year commitments, unlike On-demand.
  3. Final Answer:

    On-demand pricing does not offer cost savings for long-term commitment -> Option A
  4. Quick Check:

    Commitment savings = Reserved, not On-demand [OK]
Hint: Commitment savings only with Reserved pricing [OK]
Common Mistakes:
  • Thinking On-demand requires upfront payment
  • Believing On-demand instances are delayed
  • Confusing interruption with Spot pricing
5. A company runs a critical web application that must be available 24/7 with predictable costs. They also want to reduce expenses by committing to usage. Which EC2 pricing model should they choose and why?
hard
A. Spot instances, because they are cheapest and can be interrupted
B. On-demand instances, because they have no commitment and flexible pricing
C. Reserved instances, because they offer cost savings with a commitment and stable availability
D. Dedicated hosts, because they provide physical isolation

Solution

  1. Step 1: Analyze availability and cost needs

    Critical 24/7 apps need stable availability and predictable costs.
  2. Step 2: Match pricing models to needs

    Reserved instances provide cost savings with 1 or 3 year commitment and stable availability; Spot can be interrupted; On-demand is flexible but more costly.
  3. Final Answer:

    Reserved instances, because they offer cost savings with a commitment and stable availability -> Option C
  4. Quick Check:

    Critical + savings + commitment = Reserved [OK]
Hint: Stable + savings + commitment = Reserved instances [OK]
Common Mistakes:
  • Choosing Spot for critical apps despite interruptions
  • Picking On-demand for cost savings
  • Confusing Dedicated hosts with pricing benefits