29. Spot Instances & Spot Fleets

i. EC2 spot instances let you to take advantage of unused EC2 capacity in the AWS cloud. Spot instances are available at upto a 90% discount compared to on demand prices. We can use spot instances for various stateless, fault tolerant or flexible applications such as big data, containerized work loads, CI/ CD, web services, HPC and other test & development work loads.
ii. To use spot instances, we must first decide on our max. spot price. The instance will be provisional as long as the spot price is below max. spot price.
iii. The hourly spot price varies depending on capacity & region
iv. If the spot price goes about our maximum, we have 2 minutes to choose whether to stop or terminate instance.
v. Use spot block to stop our spot instances from being terminated even if the spot price goes over max. spot price we can set spot blocks for between one to six hours currently.
vi. Spot instances are useful for the following tasks: Big data & analytics, containerized workloads, CI/CD & testing, web services, image & media rendering & HPC
vii. Spot instances are not good for: Persistent workloads, critical jobs & databases.

Spot Fleets:
i. A collection of spot instances and optionally on demand instances.
ii. Spot fleet attempts to launch the number of spot instances & on-demand instances to meet the target capacity we specified in the spot fleet request.
iii. The request for spot instances if fulfilled if there is available capacity and the max price we specified in the request exceeds the current spot price.
iv. The spot fleet also attempts to maintain its target capacity fleet if your spot instances are interrupted.
v. Spot fleets will try & match the target capacity within price restraints:
a. Set up different launch pools. Define things like EC2 instance type, OS & AZ
b. We can have multiple pools & the fleet will choose the best way to implement depending on the strategy we define.
c. Spot fleet will stop launching instances once you reach your price threshold or capacity desires.

We can have following strategies with spot fleets:
i. Capacity optimized: The spot instances come from the pool with optimal capacity for the number of instances launching.
ii. Diversified: The spot instances are distributed across all pools
iii. Lowest price: The spot instances come from the pool with the lowest price. This is the default strategy.
iv. Instance pools to use count: The spot instances are distributed across the number of spot instances pools you specify. These parameters valid only when used in combination with lowest price

i. Spot instances save upto 90% of the cost of on-demand instances
ii. Useful for any type of computing where we dont need persistent storage
iii. We can block spot instances from terminating using spot block
iv. A spot fleet is a collection of spot instances, optionally on demand instances.

Question 1:
Your company uses EC2 instances to develop video distribution services. The EC2 instance polls the queue, receives transcoding requests, and uses Amazon Elastic Transcoder to run the transcoding process. If a process is interrupted by one EC2 instance, transcoding is restarted by another instance according to the queue. A lot of video processing backlogs occur during transcoding processing. When they occur, you should help get through these backlogs by increasing the EC2 instance and improving the processing capacity. These instances will only be needed until the backlog is reduced.
Choose the cost-optimal instance type for backlog processing that meets this requirement.
A. Reserved instance
B. On-demand instance
C. Spot instance
D. Dedicated instance
Answer: C
In Amazon Elastic Transcode, video transcoding jobs start in the order that the pipeline receives the requests. During the job process, many variables such as input file size, resolution, and bit rate affect the conversion speed. For example, a 10-minute video transcoding operation with an iPhone 4 preset is about 5 minutes. When Amazon Elastic Transcode accepts a large number of jobs, the jobs are queued up as a backlog (in the queue).
In this scenario, it is necessary to temporarily increase the number of instances for transcoding processing in order to suppress the occurrence of backlog. The best instance type is Spot Instances because this additional processing need is only temporary. Spot instances are typically used for temporary processing such as batch processing jobs. Therefore, option 3 is the correct answer for this situation.
Option 1 is incorrect. Reserved Instances are an option to purchase EC2 Instances that is discounted because its booked for a long-term use period of 1 or 3 years. It is not suitable for temporary processing like this in the scenario.
Option 2 is incorrect. On-demand instances are also an option, but they do not meet the cost-optimal requirement.
Option 4 is incorrect. Dedicated instances are used when you want to occupy a physical host server. It does not meet the cost optimization requirement due to its high cost.

Question 2:
A company runs a large batch processing job at the end of every quarter. The processing job runs for 5 days and uses 15 Amazon EC2 instances. The processing must run uninterrupted for 5 hours per day. The company is investigating ways to reduce the cost of the batch processing job.
Which pricing model should the company choose?
A. Scheduled reserved instances
B. Reserved instances
C. Spot block instances
D. On-demand instances
Answer: C
Spot Instances with a defined duration (also known as Spot blocks) are designed not to be interrupted and will run continuously for the duration you select. This makes them ideal for jobs that take a finite time to complete, such as batch processing, encoding and rendering, modeling and analysis, and continuous integration.
Spot Block is the best solution for this job as it only runs once a quarter for 5 days and therefore reserved instances would not be beneficial. Note that the maximum duration of a Spot Block is 6 hours.
CORRECT: “Spot Block Instances” is the correct answer.
INCORRECT: “Reserved Instances” is incorrect. Reserved instances are good for continuously running workloads that run for a period of 1 or 3 years.
INCORRECT: “On-Demand Instances” is incorrect. There is no cost benefit to using on-demand instances.
INCORRECT: “Scheduled Reserved Instances” is incorrect. These reserved instances are ideal for workloads that run for a certain number of hours each day, but not for just 5 days per quarter.

Question 3:
Amazon EC2 instances in a development environment run between 9am and 5pm Monday-Friday. Production instances run 24/7. Which pricing models should be used? (choose 2)
A. Use On-Demand instances for the production environment
B. Use scheduled reserved instances for the development environment
C. Use Spot instances for the development environment
D. Use Reserved instances for the production environment
E. Use Reserved instances for the development environment
Answer: B & D
Scheduled Instances are a good choice for workloads that do not run continuously but do run on a regular schedule. This is ideal for the development environment.
Reserved instances are a good choice for workloads that run continuously. This is a good option for the production environment.
CORRECT: “Use scheduled reserved instances for the development environment” is a correct answer.
CORRECT: “Use Reserved instances for the production environment” is also a correct answer.
INCORRECT: “Use Spot instances for the development environment” is incorrect. Spot Instances are a cost-effective choice if you can be flexible about when your applications run and if your applications can be interrupted. Spot instances are not suitable for the development environment as important work may be interrupted.
INCORRECT: “Use Reserved instances for the development environment” is incorrect as they should be used for the production environment.
INCORRECT: “Use On-Demand instances for the production environment” is incorrect. There is no long-term commitment required when you purchase On-Demand Instances. However, you do not get any discount and therefore this is the most expensive option.

Question 4:
A solutions architect is creating a system that will run analytics on financial data for 4 hours a night, 5 days a week. The analysis is expected to run for the same duration and cannot be interrupted once it is started. The system will be required for a minimum of 1 year.
Which type of Amazon EC2 instances should be used to reduce the cost of the system?
A. Spot instances
B. Standard reserved instances
C. On-demand instances
D. Scheduled reserved instances
Answer: D
Scheduled Reserved Instances (Scheduled Instances) enable you to purchase capacity reservations that recur on a daily, weekly, or monthly basis, with a specified start time and duration, for a one-year term. You reserve the capacity in advance, so that you know it is available when you need it. You pay for the time that the instances are scheduled, even if you do not use them.
Scheduled Instances are a good choice for workloads that do not run continuously, but do run on a regular schedule. For example, you can use Scheduled Instances for an application that runs during business hours or for batch processing that runs at the end of the week.
CORRECT: “Scheduled Reserved Instances” is the correct answer.
INCORRECT: “Standard Reserved Instances” is incorrect as the workload only runs for 4 hours a day this would be more expensive.
INCORRECT: “On-Demand Instances” is incorrect as this would be much more expensive as there is no discount applied.
INCORRECT: “Spot Instances” is incorrect as the workload cannot be interrupted once started. With Spot instances workloads can be terminated if the Spot price changes or capacity is required.