SPOT-FLEET and Auto Scaling

What is Spot-Fleet?

An AWS Spot Fleet is a collection of EC2 servers purchased at reduced rates by bidding at lowest price within AWS. Spot Fleet requests are made using the Spot Fleet API or through the command-line interface (CLI). Users request a Spot Fleet by specifying the maximum desired price per instance hour, target capacity and launch specifications such as the number of instances desired, instance types and availability zones. Prices of Spot Instances constantly change, but EC2 attempts to maintain the requested target capacity of the Spot Fleet. EC2 terminates Spot Instances as prices rise above user-defined settings and launches replacement instances at the new lowest-priced option available for an another acceptable instance type. AWS automates management of these instance collections. Spot Fleet requests are active until cancelled by a user.

Spot Fleet Allocation Strategy

The allocation Strategy determines how to fulfils Spot Fleet requests from the Spot instances pool.

The following are the allocation strategies:

Lowest Price:

The Spot instances come from the pool with the lowest price. This is the default strategy.

Diversified:

The Spot instances are distributed across all pools.

Spot Fleet Prerequisites

If you use the AWS Management Console to create a Spot fleet, it creates a role named aws-ec2-spot-fleet-role that grants the Spot fleet permission to bid on, launch, and terminate instances on your behalf, and specifies it in your Spot fleet request.

Creating a Spot Fleet Request

When you create a Spot fleet request, you must specify information about the Spot instances to launch, such as the instance type and the Spot price.

To create a Spot fleet request using the console

Open the Spot console at https://console.aws.amazon.com/ec2spot.

Need to click on Request Spot Instances Tab.

On the Find instance types page, do the following:

For Request type, select either Request or Request and Maintain.

For Target capacity, enter the number of units to request. You can choose instances or performance characteristics that are important to your application workload, such as vCPUs, memory, and storage.

For AMI, choose one of the basic Amazon Machine Images (AMI) provided by AWS, or choose Use custom AMI to use an AMI from our user community, the AWS Marketplace, or one of your own.

For Instance type(s), choose Select. Select the instance types that have the minimum hardware specifications that you need (vCPUs, memory, and storage).

For Allocation strategy, choose the strategy that meets your needs. For more information, see Spot Fleet Allocation Strategy.

For Network, your account supports either the EC2-Classic and EC2-VPC platforms, or the EC2-VPC platform only. To find out which platforms your account supports, see Supported Platforms.

[Existing VPC] Select the VPC.

[New VPC] Select Create new VPC to go the Amazon VPC console. When you are done, return to the wizard and refresh the list.

[EC2-Classic] Select EC2-Classic.

(Optional) For Availability Zones, the default is to let AWS choose the Availability Zones for your Spot instances. If you prefer specific Availability Zones, do the following:

[EC2-VPC] Select one or more Availability Zones. If you have more than one subnet in an Availability Zone, select the appropriate subnet from Subnet. To add subnets, select Create new subnet to go to the Amazon VPC console. When you are done, return to the wizard and refresh the list.

[EC2-Classic] Select Select specific zone/subnet, and then select one or more Availability Zones.

For Maximum price, you can use automated bidding or specify a bid price. Your Spot instances are not launched if your bid price is lower than the Spot price for the instance types that you selected.

Choose Next.

On the Configure page, do the following:

(Optional) To replace unhealthy instances in a Request and Maintain Spot fleet, select Replace unhealthy instances.

(Optional) If you have any start-up scripts to run, specify them using User data.

(Optional) If you need to connect to your instances, specify your key pair using Key pair name.

(Optional) If you need to launch your Spot instances with an IAM role, specify the role using IAM instance profile.

For Security groups, choose one or more security groups.

[EC2-VPC] If you need to connect to your instances in a VPC, select Enable forAuto-assign IPv4 Public IP.

By default, the request remains in effect until it is fulfilled or you cancel it. To create a request that is valid only during a specific time period, edit Request valid from and Request valid to.

(Optional) By default, we terminate your Spot instances when the request expires. To keep them running after your request expires, clear Terminate instances at expiration.

Choose Review.

On the Review page, verify the launch configuration. To make changes, choose Previous. To download a copy of the launch configuration for use with the AWS CLI, choose JSON config. When you are ready, choose Launch.

On the confirmation page, choose OK. The request type is fleet. When the request is fulfilled, requests of type instance are added, where the state is active and the status is fulfilled.

To create a Spot fleet request using the AWS CLI

Use the following request-spot-fleet command to create a Spot fleet request:

aws ec2 request-spot-fleet –spot-fleet-request-config file://config.json

For example configuration files, see Spot Fleet Example Configurations.

The following is example output:

{ “SpotFleetRequestId”: “sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE” }

Here we Completed with Spot-Fleet but if we need to configure Auto scaling during Load or Heavy Traffic then we need to configure Auto Scaling Which we will discuss in following Topic of Auto Scaling .

What is Auto scaling?

Auto Scaling helps you maintain application availability and allows you to scale your Amazon EC2 capacity up or down automatically according to conditions you define. Auto Scaling can also automatically increase the number of Amazon EC2 instances during demand spikes to maintain performance and decrease capacity after spike gone to reduce costs.

Features and Benefits

Maintain your Amazon EC2 instance availability

Whether you are running one Amazon EC2 instance or thousands, you can use Auto Scaling to detect impaired Amazon EC2 instances and unhealthy applications, and replace the instances without your intervention. This ensures that your application is getting the compute capacity that you expect.

Automatically Scale Your Amazon EC2 Fleet

Auto Scaling enables you to follow the demand curve for your applications closely, reducing the need to manually provision Amazon EC2 capacity in advance. For example, you can set a condition to add new Amazon EC2 instances in increments to the Auto Scaling group when the average utilization of your Amazon EC2 fleet is high; and similarly, you can set a condition to remove instances in the same increments when CPU utilization is low. If you have predictable load changes, you can set a schedule through Auto Scaling to plan your scaling activities. You can use Amazon Cloud Watch to send alarms to trigger scaling activities and Elastic Load Balancing to help distribute traffic to your instances within Auto Scaling groups. Auto Scaling enables you to run your Amazon EC2 fleet at optimal utilization.

Automatic Scaling for Spot Fleet

Automatic scaling is the ability to increase or decrease the target capacity of your Spot fleet automatically based on demand. A Spot fleet can either launch instances (scale out) or terminate instances (scale in), within the range that you choose, in response to one or more scaling policies. We recommend that you create two policies, one for scaling out and one for scaling in.

A scaling policy uses CloudWatch alarms to trigger the scaling process. For example, if you want to scale out when CPU utilization reaches a certain level, create an alarm using the CPUUtilization metric provided by Amazon EC2.

When you create a scaling policy, you must specify one of the following scaling adjustment types:

* Add — Increase the target capacity of the fleet by a specified number of capacity units or a specified percentage of the current capacity.

* Remove — Decrease the target capacity of the fleet by a specified number of capacity units or a specified percentage of the current capacity.

* Set to — Set the target capacity of the fleet to the specified number of capacity units.

When an alarm is triggered, the auto scaling process calculates the new target capacity using the fulfilled capacity and the scaling policy, and then updates the target capacity accordingly. For example, suppose that the target capacity and fulfilled capacity are 10 and the scaling policy adds 1. When the alarm is triggered, the auto scaling process adds 1 to 10 to get 11, so Spot fleet launches 1 instance.

Limits

* The Spot fleet request must have a request type of maintain. Automatic scaling is not supported for one-time requests or Spot blocks.

Prerequisites

* Consider which CloudWatch metrics are important to your application. You can create CloudWatch alarms based on metrics provided by AWS or your own custom metrics.

* For the AWS metrics that you will use in your scaling policies, enable CloudWatch metrics collection if the service that provides the metrics does not enable it by default.

* If you use the AWS Management Console to enable automatic scaling for your Spot fleet, it creates a role named aws-ec2-spot-fleet-autoscale-role that grants Auto Scaling permission to describe the alarms for your policies, monitor the current capacity of the fleet, and modify the capacity of the fleet. If you configure automatic scaling using the AWS CLI or an API, you can use this role if it exists, or manually create your own role for this purpose as follows.

* Open the IAM console at https://console.aws.amazon.com/iam/.

* In the navigation pane, choose Roles.

* Choose Create New Role.

* On the Set Role Name page, type a name for the role and then choose Next Step.

* On the Select Role Type page, choose Select next to Amazon EC2.

* On the Attach Policy page, select the AmazonEC2SpotFleetAutoscaleRole policy and then choose Next Step.

* On the Review page, choose Create Role.

* Select the role that you just created.

* On the Trust Relationships tab, choose Edit Trust Relationship.

* Change ec2.amazonaws.com to application-autoscaling.amazonaws.comand then choose Update Trust Policy.

To create a CloudWatch alarm

1. Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

2. In the navigation pane, choose Alarms.

3. Choose Create Alarm.

4. For CloudWatch Metrics by Category, choose a category. For example, choose EC2 Spot Metrics, Fleet Request Metrics.

5. Select a metric, and then choose Next.

6. For Alarm Threshold, type a name and description for the alarm, and set the threshold value and number of time periods for the alarm.

7. (Optional) To receive notification of a scaling event, for Actions, choose New list and type your email address. Otherwise, you can delete the notification now and add one later if needed.

8. Choose Create Alarm.

To configure automatic scaling for your Spot fleet using the console 1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

2. In the navigation pane, choose Spot Requests.

3. Select your Spot fleet request, and then choose the Auto Scaling tab.

4. If automatic scaling is not configured, choose Configure.

5. Use Scale capacity between to set the minimum and maximum capacity for your fleet. Automatic scaling will not scale your fleet below the minimum capacity or above the maximum capacity.

6. Initially, Scaling policies contains policies named ScaleUp and ScaleDown. You can complete these policies, or choose Remove policy to delete them. You can also choose Add policy to add a policy.

7. To define a policy, do the following:

a. For Policy name, type a name for the policy.

b. For Policy trigger, select an existing alarm or choose Create new alarm to open the Amazon CloudWatch console and create an alarm.

c. For Modify capacity, select a scaling adjustment type, select a number, and select a unit.

d. (Optional) To perform step scaling, choose Define steps. By default, an add policy has a lower bound of -infinity and an upper bound of the alarm threshold. By default, a remove policy has a lower bound of the alarm threshold and an upper bound of +infinity. To add another step, choose Add step.

e. (Optional) To modify the default value for the cooldown period, select a number from Cooldown period.

8. Choose Save.

Reference:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-automatic-scaling.html


 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s