What is AWS EC2?
AWS EC2 provides computing power in the cloud. At the heart of the service are EC2 instances—virtual machines that run an operating system on resources such as CPU, memory, and persistent storage. EC2 makes it easy to provision instances in seconds, run software on them, and scale them up and down as needed.
When you launch an EC2 instance, you choose an instance type (such as c5d) and size (such as “xlarge”). This determines the machine’s resource capacity and hourly price. You can do this manually through the AWS Management Console, or programmatically through the CLI or EC2 API. You pay only for instances that are running, so when you’re done using an instance, you can stop it and conserve costs.
This is part of a series of articles about AWS cost.
In this article:
- 5 EC2 Pricing Models
- 5 Best Practices To Reduce Your EC2 Costs
5 EC2 Pricing Models
1. On-Demand Pricing
You can use EC2 instances on demand, which gives you the flexibility to start and stop instances at will. However, this comes at a higher per-hour price. If you are willing to give up this flexibility and either commit to the long term (via reserved instances) or use instances that are currently underused in EC2 (spot instances), you can obtain discounts of up to 90%.
Common use cases: Applications with unexpected peak loads or experiencing high growth.
2. Reserved Instances (RI)
This pricing model allows you to commit to future use of AWS resources. AWS offers discounts of up to 72% for this program. Commitments are for either one or three years.
AWS offers standard and convertible reserved instances for EC2. The most flexible option is a convertible RI, which lets you switch instance types and sizes over the course of the commitment period.
Common use cases: Applications that have stable long-term demand or predictable usage.
3. Spot Instances
With EC2 spot instances, you can request EC2 instances based on spare capacity and receive up to 90% off on-demand pricing. Spot instances do not require long-term contracts or upfront payments.
AWS sells its available spare capacity as spot instances. These are normal instances that are not used by other customers. However, the instances can be interrupted at short notice – the EC2 platform notifies 2 minutes in advance when the instance is no longer available, and requires customers to move workloads to another instance.
Common use cases: Because spot instances do not have an SLA, it is difficult to use them for production workloads. Use cases for spot instances include batch jobs which can easily be restarted, and fault tolerant applications.
4. Savings Plans
AWS Savings Plans is a flexible pricing model that allows users to commit to specific usage at a discounted price. With AWS Savings Plans, users pay a fixed hourly rate for 1 or 3 years.
There are two types of savings plans.
- EC2 Savings Plan—available for instances in select regions and offers discounts of up to 72%. This is ideal for stable applications that are not likely to change over time.
- Compute Savings Plans—allow you to purchase compute time for EC2 instances, Lambda, and Fargate. Flexible and suitable for large organizations that might have changing resource requirements, but a consistent cloud spend.
5. Dedicated Hosts
A dedicated host is a physical server used only by specific Amazon users. This pricing approach is suitable for companies that want to minimize hardware sharing, for performance, security, or compliance reasons.
This plan bills users on an hourly rate rather than the per-second rate used for on-demand instances. Like on-demand instances, you can save up to 70% off the on-demand hourly rate by purchasing a 1-year or 3-year subscription.
With the Dedicated Host Savings Plan, you can save up to 72% on on-demand pricing for dedicated hosts.
5 Best Practices To Reduce Your EC2 Costs
1. Define Your Requirements
Computing costs are the biggest item on most cloud bills, so be careful to order only what you actually need. Consider the following dimensions when planning compute costs:
- Number of CPUs
- Processor architecture
- SSD storage
- Communications network
When you have identified the exact needs for each workload, find a set of target instance types that match them. Don’t pick the first “good enough” instance. EC2 instances have different price/performance ratios, and you get higher performance and lower cost by carefully selecting an instance type for each workload.
2. Use Tags To Target Cost Optimization
Many of the most powerful strategies for reducing EC2 costs involve targeting some EC2 instances and not others. For example, you can perform specific optimization actions on production instances, non-production instances, and batch processing jobs.
Use tags to find and optimize EC2 instances in the AWS console and AWS API. This allows you to reduce EC2 costs by controlling resources in groups. Labeling is also important for security and compliance.
Learn more in our detailed guide to AWS cost optimization
3. Use Spot Instances for Stateless and Non-production Workloads
Spot instances are EC2 instances that can be purchased at a low price. For stateless, non-production workloads, use EC2 spot instances instead of regular instances, with up to 90% cost optimization. However, take into account that spot instances may be terminated prior to production use if Amazon’s spare capacity runs out.
4. Leverage GPU Instances
When running machine learning or deep learning workloads, use Amazon’s newer GPU instances, such as the P3 or G3 series. GPU instances cost more per hour, but training machine learning models can be much faster. This helps reduce overall costs, because you will end up using less instance hours.
5. Move Cold Data to Cheaper Storage Tiers
S3 Infrequent Access, S3 Glacier, and S3 Deep Archive Glacier are tiers provided by Amazon S3 for infrequently accessed data. Data that is no longer needed in production can be automatically identified (using AWS services) and moved to the lowest cost cold storage tier. Cold storage can reduce your storage cost per GB from $0.023 to as low as $0.00099.