Class: AWSCDK::Autoscaling::InstancesDistribution

Inherits:
Jsii::Struct
  • Object
show all
Defined in:
autoscaling/instances_distribution.rb

Overview

InstancesDistribution is a subproperty of MixedInstancesPolicy that describes an instances distribution for an Auto Scaling group.

The instances distribution specifies the distribution of On-Demand Instances and Spot Instances, the maximum price to pay for Spot Instances, and how the Auto Scaling group allocates instance types to fulfill On-Demand and Spot capacities.

For more information and example configurations, see Auto Scaling groups with multiple instance types and purchase options in the Amazon EC2 Auto Scaling User Guide:

https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-purchase-options.html

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(on_demand_allocation_strategy: nil, on_demand_base_capacity: nil, on_demand_percentage_above_base_capacity: nil, spot_allocation_strategy: nil, spot_instance_pools: nil, spot_max_price: nil) ⇒ InstancesDistribution

Returns a new instance of InstancesDistribution.

Parameters:

  • on_demand_allocation_strategy (AWSCDK::Autoscaling::OnDemandAllocationStrategy, nil) (defaults to: nil)

    Indicates how to allocate instance types to fulfill On-Demand capacity.

  • on_demand_base_capacity (Numeric, nil) (defaults to: nil)

    The minimum amount of the Auto Scaling group's capacity that must be fulfilled by On-Demand Instances.

  • on_demand_percentage_above_base_capacity (Numeric, nil) (defaults to: nil)

    Controls the percentages of On-Demand Instances and Spot Instances for your additional capacity beyond OnDemandBaseCapacity.

  • spot_allocation_strategy (AWSCDK::Autoscaling::SpotAllocationStrategy, nil) (defaults to: nil)

    If the allocation strategy is lowest-price, the Auto Scaling group launches instances using the Spot pools with the lowest price, and evenly allocates your instances across the number of Spot pools that you specify.

  • spot_instance_pools (Numeric, nil) (defaults to: nil)

    The number of Spot Instance pools to use to allocate your Spot capacity.

  • spot_max_price (String, nil) (defaults to: nil)

    The maximum price per unit hour that you are willing to pay for a Spot Instance.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'autoscaling/instances_distribution.rb', line 22

def initialize(on_demand_allocation_strategy: nil, on_demand_base_capacity: nil, on_demand_percentage_above_base_capacity: nil, spot_allocation_strategy: nil, spot_instance_pools: nil, spot_max_price: nil)
  @on_demand_allocation_strategy = on_demand_allocation_strategy
  Jsii::Type.check_type(@on_demand_allocation_strategy, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfYXV0b3NjYWxpbmcuT25EZW1hbmRBbGxvY2F0aW9uU3RyYXRlZ3kifQ==")), "onDemandAllocationStrategy") unless @on_demand_allocation_strategy.nil?
  @on_demand_base_capacity = on_demand_base_capacity
  Jsii::Type.check_type(@on_demand_base_capacity, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "onDemandBaseCapacity") unless @on_demand_base_capacity.nil?
  @on_demand_percentage_above_base_capacity = on_demand_percentage_above_base_capacity
  Jsii::Type.check_type(@on_demand_percentage_above_base_capacity, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "onDemandPercentageAboveBaseCapacity") unless @on_demand_percentage_above_base_capacity.nil?
  @spot_allocation_strategy = spot_allocation_strategy
  Jsii::Type.check_type(@spot_allocation_strategy, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfYXV0b3NjYWxpbmcuU3BvdEFsbG9jYXRpb25TdHJhdGVneSJ9")), "spotAllocationStrategy") unless @spot_allocation_strategy.nil?
  @spot_instance_pools = spot_instance_pools
  Jsii::Type.check_type(@spot_instance_pools, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJudW1iZXIifQ==")), "spotInstancePools") unless @spot_instance_pools.nil?
  @spot_max_price = spot_max_price
  Jsii::Type.check_type(@spot_max_price, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "spotMaxPrice") unless @spot_max_price.nil?
end

Instance Attribute Details

#on_demand_allocation_strategyAWSCDK::Autoscaling::OnDemandAllocationStrategy? (readonly)

Note:

Default: OnDemandAllocationStrategy.PRIORITIZED

Indicates how to allocate instance types to fulfill On-Demand capacity.

The only valid value is prioritized, which is also the default value.



44
45
46
# File 'autoscaling/instances_distribution.rb', line 44

def on_demand_allocation_strategy
  @on_demand_allocation_strategy
end

#on_demand_base_capacityNumeric? (readonly)

Note:

Default: 0

The minimum amount of the Auto Scaling group's capacity that must be fulfilled by On-Demand Instances.

This base portion is provisioned first as your group scales. Defaults to 0 if not specified. If you specify weights for the instance types in the overrides, set the value of OnDemandBaseCapacity in terms of the number of capacity units, and not the number of instances.

Returns:

  • (Numeric, nil)


54
55
56
# File 'autoscaling/instances_distribution.rb', line 54

def on_demand_base_capacity
  @on_demand_base_capacity
end

#on_demand_percentage_above_base_capacityNumeric? (readonly)

Note:

Default: 100

Controls the percentages of On-Demand Instances and Spot Instances for your additional capacity beyond OnDemandBaseCapacity.

Expressed as a number (for example, 20 specifies 20% On-Demand Instances, 80% Spot Instances). Defaults to 100 if not specified. If set to 100, only On-Demand Instances are provisioned.

Returns:

  • (Numeric, nil)


62
63
64
# File 'autoscaling/instances_distribution.rb', line 62

def on_demand_percentage_above_base_capacity
  @on_demand_percentage_above_base_capacity
end

#spot_allocation_strategyAWSCDK::Autoscaling::SpotAllocationStrategy? (readonly)

Note:

Default: SpotAllocationStrategy.LOWEST_PRICE

If the allocation strategy is lowest-price, the Auto Scaling group launches instances using the Spot pools with the lowest price, and evenly allocates your instances across the number of Spot pools that you specify.

Defaults to lowest-price if not specified.

If the allocation strategy is capacity-optimized (recommended), the Auto Scaling group launches instances using Spot pools that are optimally chosen based on the available Spot capacity. Alternatively, you can use capacity-optimized-prioritized and set the order of instance types in the list of launch template overrides from highest to lowest priority (from first to last in the list). Amazon EC2 Auto Scaling honors the instance type priorities on a best-effort basis but optimizes for capacity first.



76
77
78
# File 'autoscaling/instances_distribution.rb', line 76

def spot_allocation_strategy
  @spot_allocation_strategy
end

#spot_instance_poolsNumeric? (readonly)

Note:

Default: 2

The number of Spot Instance pools to use to allocate your Spot capacity.

The Spot pools are determined from the different instance types in the overrides. Valid only when the Spot allocation strategy is lowest-price. Value must be in the range of 1 to 20. Defaults to 2 if not specified.

Returns:

  • (Numeric, nil)


85
86
87
# File 'autoscaling/instances_distribution.rb', line 85

def spot_instance_pools
  @spot_instance_pools
end

#spot_max_priceString? (readonly)

Note:

Default: "" - On-Demand price

The maximum price per unit hour that you are willing to pay for a Spot Instance.

If you leave the value at its default (empty), Amazon EC2 Auto Scaling uses the On-Demand price as the maximum Spot price. To remove a value that you previously set, include the property but specify an empty string ("") for the value.

Returns:

  • (String, nil)


94
95
96
# File 'autoscaling/instances_distribution.rb', line 94

def spot_max_price
  @spot_max_price
end

Class Method Details

.jsii_propertiesObject



96
97
98
99
100
101
102
103
104
105
# File 'autoscaling/instances_distribution.rb', line 96

def self.jsii_properties
  {
    :on_demand_allocation_strategy => "onDemandAllocationStrategy",
    :on_demand_base_capacity => "onDemandBaseCapacity",
    :on_demand_percentage_above_base_capacity => "onDemandPercentageAboveBaseCapacity",
    :spot_allocation_strategy => "spotAllocationStrategy",
    :spot_instance_pools => "spotInstancePools",
    :spot_max_price => "spotMaxPrice",
  }
end

Instance Method Details

#to_jsiiObject



107
108
109
110
111
112
113
114
115
116
117
118
# File 'autoscaling/instances_distribution.rb', line 107

def to_jsii
  result = {}
  result.merge!({
    "onDemandAllocationStrategy" => @on_demand_allocation_strategy,
    "onDemandBaseCapacity" => @on_demand_base_capacity,
    "onDemandPercentageAboveBaseCapacity" => @on_demand_percentage_above_base_capacity,
    "spotAllocationStrategy" => @spot_allocation_strategy,
    "spotInstancePools" => @spot_instance_pools,
    "spotMaxPrice" => @spot_max_price,
  })
  result.compact
end