This paper provides an overview of Amazon EC2 Spot Instances, as well as best practices for using them effectively.
When to Use Spot Instances
Spot Instances is the fourth Amazon Elastic Compute Cloud (Amazon EC2) pricing model. With Spot Instances, you can use spare Amazon EC2 computing capacity at discounts of up to 90% compared to On-Demand pricing. Unlike Reserved Instances or Savings Plans, Spot Instance do not require a commitment in order to achieve cost savings. Because they can be terminated by EC2 if there is no available capacity in the capacity pool, they are best suited for flexible workloads.
How to Launch Spot Instances
The most recommended service for launching Spot Instances is Amazon EC2 Auto Scaling. If you require more flexibility, have built your own instance launch workflows, or want to control individual aspects of the instance launches or the scaling mechanisms, you can use EC2 Fleet in Instant mode. When you use AWS services for running your cloud workloads, you can also use them for launching Spot Instances. Examples include Amazon EMR, Amazon EKS, Amazon ECS, AWS Batch, and AWS Elastic Beanstalk.
How Spot Instances Work
Amazon's Spot Instances can be interrupted by Amazon EC2 when EC2 needs the capacity back. When EC2 interrupts your Spot Instance, it either terminates, stops, or hibernates the instance, depending on the interruption behavior that you choose. You're not charged for the first hour of running time if you stop or terminate your Spot instance. If you pay for any partial hour used (as you do for On-Demand or Reserved Instances), you will have to pay for the full hour. The Spot price for each instance type in each Availability Zone is determined by long-term trends in supply and demand for EC2 spare capacity. You pay the Spot price that is in effect, billed to the nearest second. We recommend that you do not specify a maximum price, but rather let the maximum price default to the On-Demand price. A high maximum price does not increase your chances of launching a Spot Instance.
Managing Spot Instance Interruptions
Amazon EC2 instance rebalance recommendations is a signal that notifies you when a Spot Instance is at elevated risk of interruption also Spot Instance interruption notices can help you manage your application to be fault tolerant.
You can decide to rebalance your workload to new or existing Spot Instances that are not at an elevated risk of interruption. You can take advantage of EC2's Capacity Rebalancing feature in EC2 Auto Scaling groups.
Spot Instance Limits
There is a limit on the number of running and requested Spot Instances per AWS account per region. There are six Spot Instance limits, listed in the following table. Each limit specifies the vCPU limit for one or more instance families. If you terminate your Spot instances but do not cancel the requests, the requests count against your Spot Instances vCPU limit until Amazon EC2 detects the terminations and closes them.
With vCPU limits, you can use your limit in terms of the number of vCPUs that are required to launch any combination of instance types that meet your changing application needs. With an All-Standard Spot Instance Requests limit of 256 vCPUs, you could request 32 m5.2xlarge Spot Instances (32 x 8 vCPU) or 16 c5.4xlarge spot instances (16 x 16 vPCs) or a combination of all sizes that total 256 vCPU's.
Spot Instance Best Practices
Your instance type requirements, budget requirements, and application design will determine how to apply the following best practices for your application:
•Be flexible about instance types. A Spot Instance pool is a set of unused EC2 instances with the same instance type and Availability Zone. You should be flexible about which instance types you request and in which Availability Zones you can deploy your workload. Don't just ask for c5.large if you'd be willing to use larges from the c4, m5, and m4 families.
• Use the capacity optimized allocation strategy Allocation strategies in EC2 Auto Scaling groups help you to provision your target capacity without the need to manually look for the Spot Instance pools with spare capacity. We recommend using the capacity optimized strategy because this strategy automatically provisions instances from the most-available Spot Instances pools. Because your Spot Instancy capacity is sourced from pools with optimal capacity, this decreases the possibility that your spot Instances are interrupted.
• Use proactive capacity rebalancing. Capacity Rebalancing helps you maintain workload availability by proactively augmenting your Auto Scaling group with a new Spot Instance before a running Spot Instances receives the two-minute interruption notice. When capacity rebalancing is enabled, auto-scaling attempts to proactively replace Spot instances that have received a rebalance recommendation. This gives you the opportunity to rebalance your workload to new spots that are not at elevated risk of interruption.
• Use integrated AWS services to manage your Spot Instances. Other AWS services integrate with Spot to reduce overall compute costs without the need to manage the individual instances or fleets. We recommend that you consider the following solutions for your applicable workloads: Amazon EMR, Amazon ECS, AWS Batch, Amazon EKS, SageMaker, AWS Elastic Beanstalk, and Amazon GameLift.
• Choose the modern and correct launch tool for Spot Instances. If you need to build your application with control over the launch of Spot Instances, use the right tool. For most workloads, you should use EC2 Auto Scaling because it supplies a more comprehensive feature set for a wide variety of workloads. If you need more control over individual requests and are looking for a "launch only" tool, try EC2 Fleet in Instant mode.
Spot Integration with Other AWS Services
Amazon EMR Integration
You can run Amazon EMR clusters on Spot Instances and significantly reduce the cost of processing vast amounts of data for your analytics workloads. You can easily mix Spot Instance with On-Demand and Reserved Instances using the EMR Instance Fleets feature.
EC2 Auto Scaling Integration
You can use Amazon EC2 Auto Scaling groups to launch and manage Spot Instances, maintain application availability, diversify instance type and purchase option (On-Demand/Spot) selection, and scale your Amazon EC2 capacity using dynamic, scheduled, and predictive scaling policies.
Amazon EKS Integration
Amazon EKS is a cloud computing platform that lets you cost-optimize your Kubernetes-based workloads. EKS managed node groups manage the entire Spot Instance lifecycle, by replacing soon-to-be-interrupted Spot Instances with newly launched instances. This reduces the chances of impact on application performance or availability when EC2 is interrupted.
Amazon ECS Integration
You can run Amazon ECS clusters on Spot Instances to reduce the operational cost of running containerized applications. Amazon ECS supports automatic draining of Spot Instances that are soon-to-be interrupted.
Amazon ECS with AWS Fargate Spot Integration
If your containerized tasks are interruptible and flexible, you can choose to run your ECS tasks with the AWS Fargate Spot capacity provider, meaning that your tasks will run on AWS Fargate, a serverless containers platform, and you will benefit from cost savings driven by Fargate Spot
Amazon Batch Integration
AWS Batch plans, schedules, and executes your batch computing workloads on AWS. AWS Batch dynamically requests Spot Instances on your behalf, reducing the cost of running your batch jobs.
Amazon SageMaker Integration
Amazon SageMaker makes it easy to train machine learning models using managed Spot Instances. Managed Spot training can optimize the cost of training models by up to 90% over On-Demand Instances. SageMaker manages the Spot interruptions on your behalf.
Amazon Gamelift Integration
Amazon GameLift is a game server hosting solution that deploys, operates, and scales cloud servers for multiplayer games. Support for Spot Instances in Amazon Gamelift gives you the opportunity to significantly lower your hosting costs. When creating fleets of hosting resources, you can choose between On-Demand Instances or Spot Instances. While Spot Instances might be interrupted with two minutes of notification, Amazon GameLift's FleetIQ minimizes the chance of interruptions
AWS Elastic Beanstalk Integration
AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS. You can simply upload your code, and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, and auto scaling, to application health monitoring. You can use Spot Instances in your Elastic Beanstalk environments for cost optimizing the underlying infrastructure of your web application
Overview of Amazon EC2 Spot Instances
Top comments (0)