Skip to content

Commit

Permalink
Final edits
Browse files Browse the repository at this point in the history
  • Loading branch information
jagpk committed Nov 24, 2022
1 parent 5ed7127 commit 88d2ac2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 52 deletions.
14 changes: 10 additions & 4 deletions content/launching_ec2_spot_instances/final_thoughts.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
+++
title = "Final Thoughts"
title = "Learn more"
weight = 210
+++

If you want to learn more about all the benefits of Auto Scaling groups, you can find more information in the [Amazon EC2 Auto Scaling group documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html).
#### Auto Scaling group
Learn more about all the benefits of Auto Scaling groups in the [Amazon EC2 Auto Scaling group documentation](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html).

If you want to learn more about EC2 Fleets, you can find more information in the [Amazon EC2 Fleet documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet.html).
#### EC2 Fleet
Learn more about EC2 Fleets in the [Amazon EC2 Fleet documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet.html).

You can learn more about Spot Interruption in AWS FIS by reading the [blog post](https://aws.amazon.com/blogs/compute/implementing-interruption-tolerance-in-amazon-ec2-spot-with-aws-fault-injection-simulator/).
#### Spot interruptions with FIS
Learn more about Spot Interruption in AWS FIS in the [Implementing interruption tolerance in Amazon EC2 Spot with AWS Fault Injection Simulator](https://aws.amazon.com/blogs/compute/implementing-interruption-tolerance-in-amazon-ec2-spot-with-aws-fault-injection-simulator/) blog post.

#### Cost management
Learn more about Cost Management tools in the [Diving Deep into EC2 Spot Instance Cost and Operational Practices](https://aws.amazon.com/blogs/compute/diving-deep-into-ec2-spot-instance-cost-and-operational-practices/) blog post.
4 changes: 2 additions & 2 deletions content/launching_ec2_spot_instances/fis_experiment.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Note: Currently, AWS FIS has a Service Quota of maximum of 5 resources per exper

To use AWS FIS, you run experiments on your AWS resources to test your theory of how an application or system will perform under fault conditions. To run experiments, you first create an experiment template. An experiment template is the blueprint of your experiment. It contains the actions, targets, and stop conditions for the experiment.

In this section, you create 1) an IAM role that grants AWS FIS the permissions to execute the experiment, 2) create a FIS experiment template, and 3) run the experiment to trigger Spot Instance interruption.
In this section, you 1) create an IAM role that grants AWS FIS the permissions to execute the experiment, 2) create a FIS experiment template, and 3) and run the experiment to trigger Spot Instance interruption.

#### Create an IAM Role for AWS FIS

Expand Down Expand Up @@ -173,7 +173,7 @@ To run the experiment, you use `start-experiment` command to run the template cr
aws fis start-experiment --experiment-template-id $FIS_TEMPLATE_ID
```
After you run the experiment, you will see that 50% of the Spot Instances launched by the Auto Scaling group receive the Rebalance Recommendation signals. Note that this is less than the Service Quota of 5, which is the maximum number of EC2 Spot instance that can be interrupted by a single experiment. When the actions on this experiment is complete:
As the result of this experiment, you see that 50% of the Spot Instances launched by the Auto Scaling group receive the Rebalance Recommendation signals. Note that this is less than the Service Quota of 5, which is the maximum number of EC2 Spot instance that can be interrupted by a single experiment. When the actions on this experiment is complete:
* The target Spot Instance receives an instance rebalance recommendation signal.
* A Spot instance interruption notice is issued two minutes before Amazon EC2 terminates your instance.
Expand Down
46 changes: 20 additions & 26 deletions content/launching_ec2_spot_instances/runinstances_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ title = "(Optional) - Launching an EC2 Spot Instance via the RunInstances API"
weight = 200
+++

## Launching an EC2 Spot Instance via the RunInstances API

This API allows you to launch one or more instances, using a Launch Template that you have previously configured. Typically you would use the RunInstances API to launch one or more instances of the same type in situations where you are not planning to replace or manage the instances as a group entity.

{{%notice note%}}
Even though RunInstances API allows you to launch Spot instances, it doesn't allow you to specify a replacement strategy or an allocation strategy. Remember that by specifying multiple Spot capacity pools we can apply instance diversification and by using `price-capacity-optimized` allocation strategy, Amazon EC2 will automatically launch Spot Instances from the most optimal capacity pools having the lowest Spot pool prices. This is why it is recommended to use EC2 Fleet in `instant` mode as a drop-in replacement for RunInstances API.
{{%notice warning%}}
We strongly discourage using the RunInstances API for launching Spot Instances because doesn't allow you to specify a replacement strategy or an allocation strategy. Remember that by specifying multiple Spot capacity pools you can apply instance diversification and by using `price-capacity-optimized` allocation strategy, Amazon EC2 will automatically launch Spot Instances from the most optimal capacity pools with low prices. This is why we recommended to use EC2 Fleet in `instant` mode as a drop-in replacement for RunInstances API or use Auto Scaling group to manage the instance lifecycle.
{{% /notice %}}

## RunInstance example: Launching a single instance

The most common way to launch a one-off single instance is RunInstance. We will use the Launch Template that we previously created. To launch a RunInstances on EC2 Spot you would need to create this configuration file:
RunInstances API allows you to launch one or more instances, using a launch template that you have previously configured. Typically you would use the RunInstances API to launch one or more instances of the same type in situations where you are not planning to replace or manage the instances as a group entity.

{{%notice note%}}
In this case we are adding a Tag to the newly created instance. We will use this tag to terminate the instance later on.
{{% /notice %}}
## RunInstance example: Launching a single instance

1. To launch a Spot Instance with RunInstances API you create below configuration file:

```
cat <<EoF > ./runinstances-config.json
Expand Down Expand Up @@ -48,19 +41,24 @@ cat <<EoF > ./runinstances-config.json
EoF
```

Run this command to submit the RunInstances API request:
2. Run this command to submit the RunInstances API request:

```bash
aws ec2 run-instances --cli-input-json file://runinstances-config.json
```

If the request is successful, you should see an output with the description of the instances that have been launched.

Now, how would you request a Spot instances using an EC2 Fleet?
### Challenges
Given the configuration you used above, try to answer the following questions. Click to expand and see the answers.

{{%notice info%}}
In some applications where RunInstances is used to create and manage instances replacing the RunInstance API with EC2 Fleet API helps to ensure that Spot best practices are enforced while making the minimum modifications to the application. The fact the EC2 Fleet API is also synchronous makes it more reliable than polling with asynchronous RunInstances APIs.
{{% /notice %}}

With what we have seen in the previous sections, try to perform the API call following Spot best practices (diversification, allocation strategy, etc). When you are ready, click on *Show me the answer* to see how you have done.
{{%expand "1. Do you know how to replace this Spot Instance with same launch parameters as above example with EC2 Fleet?" %}}

{{%expand "Show me the answer:" %}}
Based on the previous sections, try to perform the API call following Spot best practices (diversification, allocation strategy, etc).

Configuration file for placing the request:

Expand All @@ -81,27 +79,27 @@ cat <<EoF > ./ec2-fleet-replacement-config.json
},
"Overrides":[
{
"InstanceType":"c5.xlarge",
"InstanceType":"c5.large",
"Priority": 6.0
},
{
"InstanceType":"m5.xlarge",
"InstanceType":"m5.large",
"Priority": 5.0
},
{
"InstanceType":"r5.xlarge",
"InstanceType":"r5.large",
"Priority": 4.0
},
{
"InstanceType":"c5.large",
"InstanceType":"c5a.large",
"Priority": 3.0
},
{
"InstanceType":"m5.large",
"InstanceType":"m5a.large",
"Priority": 2.0
},
{
"InstanceType":"r5.large",
"InstanceType":"r5a.large",
"Priority": 1.0
}
]
Expand Down Expand Up @@ -140,7 +138,3 @@ aws ec2 describe-instances --filters Name=instance-lifecycle,Values=spot Name=ta
```

{{% /expand %}}

In some applications where RunInstances was used to create and manage instances, this technique of replacing the RunInstance call with EC2 Fleet helps to ensure that Spot best practices are enforced while making the minimum modifications to the application. The fact the call is also synchronous and that shows the result of the provision capacity (Spot or On-Demand), makes it more reliable than polling with asynchronous APIs. Additionally, it provides all the diversification best practices we've seen so far in the rest of the APIs.

Our advise for those applications using still RunInstances and Spot is to consider moving to Auto Scaling Groups. Using even a Single EC2 Spot Instance in an Auto Scaling Group is a good pattern. The Auto Scaling group will replace the instance if un-healthy and manage the life-cycle according to all the best practices we've seen so far.
3 changes: 1 addition & 2 deletions content/launching_ec2_spot_instances/savings.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ You can also view the Spot Savings using [AWS Cost Explorer](https://aws.amazon.

![AWS Cost Explorer](/images/launching_ec2_spot_instances/cost_explorer.png)

AWS Customers have access to raw cost and usage data through the AWS Cost and Usage (AWS CUR) reports. These reports contain the most comprehensive information about your AWS usage and costs. If you’re using Spot Instances for your compute needs, then AWS CUR populates the Amazon EC2 Spot usage pricing/* columns and the product/* columns. With this data, you can calculate the past savings achieved with Spot through the AWS CUR.
AWS Customers have access to raw cost and usage data through the AWS Cost and Usage (AWS CUR) reports. These reports contain the most comprehensive information about your AWS usage and costs. If you’re using Spot Instances for your compute needs, then AWS CUR populates the Amazon EC2 Spot usage pricing columns and the product columns. With this data, you can calculate the past savings achieved with Spot through the AWS CUR.

For more information on Cost Management Tools, you can read the [Diving Deep into EC2 Spot Instance Cost and Operational Practices blog](https://aws.amazon.com/blogs/compute/diving-deep-into-ec2-spot-instance-cost-and-operational-practices/)
Loading

0 comments on commit 88d2ac2

Please sign in to comment.