# SpotOptionsRequestProperty

Specifies the configuration of Spot Instances for an EC2 Fleet.

`SpotOptionsRequest` is a property of the [AWS::EC2::EC2Fleet](https://docs.aws.amazon.com//AWSCloudFormation/latest/UserGuide/aws-resource-ec2-ec2fleet.html) resource.

- Source: Generated at build time
- Type last changed: v2.93.0 · 23 Aug 2023

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
const spotOptionsRequestProperty: ec2.CfnEC2Fleet.SpotOptionsRequestProperty = {
  allocationStrategy: 'allocationStrategy',
  instanceInterruptionBehavior: 'instanceInterruptionBehavior',
  instancePoolsToUseCount: 123,
  maintenanceStrategies: {
    capacityRebalance: {
      replacementStrategy: 'replacementStrategy',
      terminationDelay: 123,
    },
  },
  maxTotalPrice: 'maxTotalPrice',
  minTargetCapacity: 123,
  singleAvailabilityZone: false,
  singleInstanceType: false,
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ec2 as ec2

spot_options_request_property = ec2.CfnEC2Fleet.SpotOptionsRequestProperty(
    allocation_strategy="allocationStrategy",
    instance_interruption_behavior="instanceInterruptionBehavior",
    instance_pools_to_use_count=123,
    maintenance_strategies=ec2.CfnEC2Fleet.MaintenanceStrategiesProperty(
        capacity_rebalance=ec2.CfnEC2Fleet.CapacityRebalanceProperty(
            replacement_strategy="replacementStrategy",
            termination_delay=123
        )
    ),
    max_total_price="maxTotalPrice",
    min_target_capacity=123,
    single_availability_zone=False,
    single_instance_type=False
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ec2.*;

SpotOptionsRequestProperty spotOptionsRequestProperty = SpotOptionsRequestProperty.builder()
        .allocationStrategy("allocationStrategy")
        .instanceInterruptionBehavior("instanceInterruptionBehavior")
        .instancePoolsToUseCount(123)
        .maintenanceStrategies(MaintenanceStrategiesProperty.builder()
                .capacityRebalance(CapacityRebalanceProperty.builder()
                        .replacementStrategy("replacementStrategy")
                        .terminationDelay(123)
                        .build())
                .build())
        .maxTotalPrice("maxTotalPrice")
        .minTargetCapacity(123)
        .singleAvailabilityZone(false)
        .singleInstanceType(false)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.EC2;

var spotOptionsRequestProperty = new SpotOptionsRequestProperty {
    AllocationStrategy = "allocationStrategy",
    InstanceInterruptionBehavior = "instanceInterruptionBehavior",
    InstancePoolsToUseCount = 123,
    MaintenanceStrategies = new MaintenanceStrategiesProperty {
        CapacityRebalance = new CapacityRebalanceProperty {
            ReplacementStrategy = "replacementStrategy",
            TerminationDelay = 123
        }
    },
    MaxTotalPrice = "maxTotalPrice",
    MinTargetCapacity = 123,
    SingleAvailabilityZone = false,
    SingleInstanceType = false
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

spotOptionsRequestProperty := &SpotOptionsRequestProperty{
	AllocationStrategy: jsii.String("allocationStrategy"),
	InstanceInterruptionBehavior: jsii.String("instanceInterruptionBehavior"),
	InstancePoolsToUseCount: jsii.Number(123),
	MaintenanceStrategies: &MaintenanceStrategiesProperty{
		CapacityRebalance: &CapacityRebalanceProperty{
			ReplacementStrategy: jsii.String("replacementStrategy"),
			TerminationDelay: jsii.Number(123),
		},
	},
	MaxTotalPrice: jsii.String("maxTotalPrice"),
	MinTargetCapacity: jsii.Number(123),
	SingleAvailabilityZone: jsii.Boolean(false),
	SingleInstanceType: jsii.Boolean(false),
}
```

## Properties

- `allocationStrategy`: string — Indicates how to allocate the target Spot Instance capacity across the Spot Instance pools specified by the EC2 Fleet.

  If the allocation strategy is `lowestPrice` , EC2 Fleet launches instances from the Spot Instance pools with the lowest price. This is the default allocation strategy.

  If the allocation strategy is `diversified` , EC2 Fleet launches instances from all the Spot Instance pools that you specify.

  If the allocation strategy is `capacityOptimized` , EC2 Fleet launches instances from Spot Instance pools that are optimally chosen based on the available Spot Instance capacity.

  *Allowed Values* : `lowestPrice` | `diversified` | `capacityOptimized` | `capacityOptimizedPrioritized`

- `instanceInterruptionBehavior`: string — The behavior when a Spot Instance is interrupted.

  Default: `terminate`

- `instancePoolsToUseCount`: number — The number of Spot pools across which to allocate your target Spot capacity.

  Supported only when Spot `AllocationStrategy` is set to `lowest-price` . EC2 Fleet selects the cheapest Spot pools and evenly allocates your target Spot capacity across the number of Spot pools that you specify.

  Note that EC2 Fleet attempts to draw Spot Instances from the number of pools that you specify on a best effort basis. If a pool runs out of Spot capacity before fulfilling your target capacity, EC2 Fleet will continue to fulfill your request by drawing from the next cheapest pool. To ensure that your target capacity is met, you might receive Spot Instances from more than the number of pools that you specified. Similarly, if most of the pools have no Spot capacity, you might receive your full target capacity from fewer than the number of pools that you specified.

- `maintenanceStrategies`: [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnEC2Fleet.MaintenanceStrategiesProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.CfnEC2Fleet.MaintenanceStrategiesProperty.html) — The strategies for managing your Spot Instances that are at an elevated risk of being interrupted.

- `maxTotalPrice`: string — The maximum amount per hour for Spot Instances that you're willing to pay.

  We do not recommend using this parameter because it can lead to increased interruptions. If you do not specify this parameter, you will pay the current Spot price.

  > If you specify a maximum price, your Spot Instances will be interrupted more frequently than if you do not specify this parameter. > If your fleet includes T instances that are configured as `unlimited` , and if their average CPU usage exceeds the baseline utilization, you will incur a charge for surplus credits. The `MaxTotalPrice` does not account for surplus credits, and, if you use surplus credits, your final cost might be higher than what you specified for `MaxTotalPrice` . For more information, see [Surplus credits can incur charges](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-performance-instances-unlimited-mode-concepts.html#unlimited-mode-surplus-credits) in the *Amazon EC2 User Guide* .

- `minTargetCapacity`: number — The minimum target capacity for Spot Instances in the fleet.

  If this minimum capacity isn't reached, no instances are launched.

  Constraints: Maximum value of `1000` . Supported only for fleets of type `instant` .

  At least one of the following must be specified: `SingleAvailabilityZone` | `SingleInstanceType`

- `singleAvailabilityZone`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates that the fleet launches all Spot Instances into a single Availability Zone.

  Supported only for fleets of type `instant` .

- `singleInstanceType`: boolean | [IResolvable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) — Indicates that the fleet uses a single instance type to launch all Spot Instances in the fleet.

  Supported only for fleets of type `instant` .
