Skip to content

modify_spot_fleet_request

modify_spot_fleet_request(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    launch_template_configs: Optional[LaunchTemplateConfigList] = None,
    on_demand_target_capacity: Optional[Integer] = None,
    context: Optional[String] = None,
    spot_fleet_request_id: Optional[SpotFleetRequestId] = None,
    target_capacity: Optional[Integer] = None,
    excess_capacity_termination_policy: Optional[
        ExcessCapacityTerminationPolicy
    ] = None,
) -> ModifySpotFleetRequestResponse

Modifies the specified Spot Fleet request.

You can only modify a Spot Fleet request of type maintain.

While the Spot Fleet request is being modified, it is in the modifying state.

To scale up your Spot Fleet, increase its target capacity. The Spot Fleet launches the additional Spot Instances according to the allocation strategy for the Spot Fleet request. If the allocation strategy is lowestPrice, the Spot Fleet launches instances using the Spot Instance pool with the lowest price. If the allocation strategy is diversified, the Spot Fleet distributes the instances across the Spot Instance pools. If the allocation strategy is capacityOptimized, Spot Fleet launches instances from Spot Instance pools with optimal capacity for the number of instances that are launching.

To scale down your Spot Fleet, decrease its target capacity. First, the Spot Fleet cancels any open requests that exceed the new target capacity. You can request that the Spot Fleet terminate Spot Instances until the size of the fleet no longer exceeds the new target capacity. If the allocation strategy is lowestPrice, the Spot Fleet terminates the instances with the highest price per unit. If the allocation strategy is capacityOptimized, the Spot Fleet terminates the instances in the Spot Instance pools that have the least available Spot Instance capacity. If the allocation strategy is diversified, the Spot Fleet terminates instances across the Spot Instance pools. Alternatively, you can request that the Spot Fleet keep the fleet at its current size, but not replace any Spot Instances that are interrupted or that you terminate manually.

If you are finished with your Spot Fleet for now, but will use it again later, you can set the target capacity to 0.

Parameters:

  • launch_template_configs (Optional[LaunchTemplateConfigList], default: None ) –

    The launch template and overrides. You can only use this parameter if you specified a launch template (LaunchTemplateConfigs) in your Spot Fleet request. If you specified LaunchSpecifications in your Spot Fleet request, then omit this parameter.

  • on_demand_target_capacity (Optional[Integer], default: None ) –

    The number of On-Demand Instances in the fleet.

  • context (Optional[String], default: None ) –

    Reserved.

  • spot_fleet_request_id (Optional[SpotFleetRequestId], default: None ) –

    The ID of the Spot Fleet request.

  • target_capacity (Optional[Integer], default: None ) –

    The size of the fleet.

  • excess_capacity_termination_policy (Optional[ExcessCapacityTerminationPolicy], default: None ) –

    Indicates whether running instances should be terminated if the target capacity of the Spot Fleet request is decreased below the current size of the Spot Fleet.

    Supported only for fleets of type maintain.

Raises:

Examples:

To increase the target capacity of a Spot fleet request This example increases the target capacity of the specified Spot fleet request.

>>> client.modify_spot_fleet_request(spot_fleet_request_id='sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE', target_capacity=20)
Source code in docs_src/capo_ec2/_services/ec2.py
def modify_spot_fleet_request(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    launch_template_configs: Optional[
        "capo_ec2.types.launch_template_config_list.LaunchTemplateConfigList"
    ] = None,
    on_demand_target_capacity: Optional["capo_ec2.types.integer.Integer"] = None,
    context: Optional["capo_ec2.types.string.String"] = None,
    spot_fleet_request_id: Optional[
        "capo_ec2.types.spot_fleet_request_id.SpotFleetRequestId"
    ] = None,
    target_capacity: Optional["capo_ec2.types.integer.Integer"] = None,
    excess_capacity_termination_policy: Optional[
        "capo_ec2.types.excess_capacity_termination_policy.ExcessCapacityTerminationPolicy"
    ] = None,
) -> "capo_ec2.types.modify_spot_fleet_request_response.ModifySpotFleetRequestResponse":
    """<p>Modifies the specified Spot Fleet request.</p> <p>You can only modify a Spot Fleet request of type <code>maintain</code>.</p> <p>While the Spot Fleet request is being modified, it is in the <code>modifying</code> state.</p> <p>To scale up your Spot Fleet, increase its target capacity. The Spot Fleet launches the additional Spot Instances according to the allocation strategy for the Spot Fleet request. If the allocation strategy is <code>lowestPrice</code>, the Spot Fleet launches instances using the Spot Instance pool with the lowest price. If the allocation strategy is <code>diversified</code>, the Spot Fleet distributes the instances across the Spot Instance pools. If the allocation strategy is <code>capacityOptimized</code>, Spot Fleet launches instances from Spot Instance pools with optimal capacity for the number of instances that are launching.</p> <p>To scale down your Spot Fleet, decrease its target capacity. First, the Spot Fleet cancels any open requests that exceed the new target capacity. You can request that the Spot Fleet terminate Spot Instances until the size of the fleet no longer exceeds the new target capacity. If the allocation strategy is <code>lowestPrice</code>, the Spot Fleet terminates the instances with the highest price per unit. If the allocation strategy is <code>capacityOptimized</code>, the Spot Fleet terminates the instances in the Spot Instance pools that have the least available Spot Instance capacity. If the allocation strategy is <code>diversified</code>, the Spot Fleet terminates instances across the Spot Instance pools. Alternatively, you can request that the Spot Fleet keep the fleet at its current size, but not replace any Spot Instances that are interrupted or that you terminate manually.</p> <p>If you are finished with your Spot Fleet for now, but will use it again later, you can set the target capacity to 0.</p>

    Args:
        launch_template_configs: <p>The launch template and overrides. You can only use this parameter if you specified a launch template (<code>LaunchTemplateConfigs</code>) in your Spot Fleet request. If you specified <code>LaunchSpecifications</code> in your Spot Fleet request, then omit this parameter.</p>
        on_demand_target_capacity: <p>The number of On-Demand Instances in the fleet.</p>
        context: <p>Reserved.</p>
        spot_fleet_request_id: <p>The ID of the Spot Fleet request.</p>
        target_capacity: <p>The size of the fleet.</p>
        excess_capacity_termination_policy: <p>Indicates whether running instances should be terminated if the target capacity of the Spot Fleet request is decreased below the current size of the Spot Fleet.</p> <p>Supported only for fleets of type <code>maintain</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To increase the target capacity of a Spot fleet request
        This example increases the target capacity of the specified Spot fleet request.

        >>> client.modify_spot_fleet_request(spot_fleet_request_id='sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE', target_capacity=20)
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.modify_spot_fleet_request_request.ModifySpotFleetRequestRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.modify_spot_fleet_request_response.ModifySpotFleetRequestResponse"
    ]:
        import capo_ec2._operations.amazon_ec2.modify_spot_fleet_request

        output, http_response = (
            capo_ec2._operations.amazon_ec2.modify_spot_fleet_request.modify_spot_fleet_request(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ModifySpotFleetRequest")
    )
    input_: capo_ec2.types.modify_spot_fleet_request_request.ModifySpotFleetRequestRequest = {}
    if launch_template_configs is not None:
        input_["launch_template_configs"] = launch_template_configs
    if on_demand_target_capacity is not None:
        input_["on_demand_target_capacity"] = on_demand_target_capacity
    if context is not None:
        input_["context"] = context
    if spot_fleet_request_id is not None:
        input_["spot_fleet_request_id"] = spot_fleet_request_id
    if target_capacity is not None:
        input_["target_capacity"] = target_capacity
    if excess_capacity_termination_policy is not None:
        input_["excess_capacity_termination_policy"] = (
            excess_capacity_termination_policy
        )

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output