0
0
AWScloud~30 mins

EC2 pricing models (on-demand, reserved, spot) in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding EC2 Pricing Models: On-Demand, Reserved, and Spot Instances
📖 Scenario: You are managing cloud resources for a small company. You want to understand how different EC2 pricing models work so you can choose the best option for your needs.
🎯 Goal: Create a simple AWS CloudFormation template that defines three EC2 instances, each using a different pricing model: On-Demand, Reserved, and Spot. This will help you see how to configure each pricing option in infrastructure as code.
📋 What You'll Learn
Define an EC2 instance with On-Demand pricing
Define an EC2 instance with Reserved pricing (using a Savings Plan or Reserved Instance equivalent)
Define an EC2 instance with Spot pricing
Use valid AWS CloudFormation syntax
Use clear and simple resource names
💡 Why This Matters
🌍 Real World
Cloud engineers often need to manage EC2 instances with different pricing models to optimize costs and availability.
💼 Career
Understanding how to configure EC2 pricing models in infrastructure as code is essential for cloud architects and DevOps engineers.
Progress0 / 4 steps
1
Create the base CloudFormation template with one On-Demand EC2 instance
Create a CloudFormation template with a resource named OnDemandInstance of type AWS::EC2::Instance. Set the InstanceType to t3.micro and use the AMI ID ami-0abcdef1234567890. This instance will use the default On-Demand pricing.
AWS
Need a hint?

Use the Resources section to define your EC2 instance. The default pricing is On-Demand, so no extra config is needed.

2
Add a Reserved EC2 instance with a tag to indicate reservation
Add a new resource named ReservedInstance of type AWS::EC2::Instance. Use the same InstanceType and ImageId as the On-Demand instance. Add a tag with Key set to PricingModel and Value set to Reserved to indicate this instance is reserved.
AWS
Need a hint?

Tags help identify the instance type. Reserved pricing is managed outside CloudFormation, so tagging is a way to mark it.

3
Add a Spot EC2 instance with Spot options
Add a resource named SpotInstance of type AWS::EC2::Instance. Use the same InstanceType and ImageId. Under Properties, add a InstanceMarketOptions section with MarketType set to spot to specify this is a Spot instance.
AWS
Need a hint?

Spot instances require the InstanceMarketOptions property with MarketType set to spot.

4
Add a Outputs section to show instance IDs
Add an Outputs section to the template. Create three outputs named OnDemandInstanceId, ReservedInstanceId, and SpotInstanceId. Each output should use Ref to return the instance ID of the corresponding resource.
AWS
Need a hint?

Outputs help you see the instance IDs after deployment. Use !Ref to get the instance IDs.