Skip to content

modify_fleet

modify_fleet(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    excess_capacity_termination_policy: Optional[
        FleetExcessCapacityTerminationPolicy
    ] = None,
    launch_template_configs: Optional[FleetLaunchTemplateConfigListRequest] = None,
    fleet_id: Optional[FleetId] = None,
    target_capacity_specification: Optional[TargetCapacitySpecificationRequest] = None,
    context: Optional[String] = None,
) -> ModifyFleetResult

Modifies the specified EC2 Fleet.

You can only modify an EC2 Fleet request of type maintain.

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

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

To scale down your EC2 Fleet, decrease its target capacity. First, the EC2 Fleet cancels any open requests that exceed the new target capacity. You can request that the EC2 Fleet terminate Spot Instances until the size of the fleet no longer exceeds the new target capacity. If the allocation strategy is lowest-price, the EC2 Fleet terminates the instances with the highest price per unit. If the allocation strategy is capacity-optimized, the EC2 Fleet terminates the instances in the Spot Instance pools that have the least available Spot Instance capacity. If the allocation strategy is diversified, the EC2 Fleet terminates instances across the Spot Instance pools. Alternatively, you can request that the EC2 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 EC2 Fleet for now, but will use it again later, you can set the target capacity to 0.

Parameters:

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

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

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

    Supported only for fleets of type maintain.

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

    The launch template and overrides.

  • fleet_id (Optional[FleetId], default: None ) –

    The ID of the EC2 Fleet.

  • target_capacity_specification (Optional[TargetCapacitySpecificationRequest], default: None ) –

    The size of the EC2 Fleet.

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

    Reserved.

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def modify_fleet(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    excess_capacity_termination_policy: Optional[
        "capo_ec2.types.fleet_excess_capacity_termination_policy.FleetExcessCapacityTerminationPolicy"
    ] = None,
    launch_template_configs: Optional[
        "capo_ec2.types.fleet_launch_template_config_list_request.FleetLaunchTemplateConfigListRequest"
    ] = None,
    fleet_id: Optional["capo_ec2.types.fleet_id.FleetId"] = None,
    target_capacity_specification: Optional[
        "capo_ec2.types.target_capacity_specification_request.TargetCapacitySpecificationRequest"
    ] = None,
    context: Optional["capo_ec2.types.string.String"] = None,
) -> "capo_ec2.types.modify_fleet_result.ModifyFleetResult":
    """<p>Modifies the specified EC2 Fleet.</p> <p>You can only modify an EC2 Fleet request of type <code>maintain</code>.</p> <p>While the EC2 Fleet is being modified, it is in the <code>modifying</code> state.</p> <p>To scale up your EC2 Fleet, increase its target capacity. The EC2 Fleet launches the additional Spot Instances according to the allocation strategy for the EC2 Fleet request. If the allocation strategy is <code>lowest-price</code>, the EC2 Fleet launches instances using the Spot Instance pool with the lowest price. If the allocation strategy is <code>diversified</code>, the EC2 Fleet distributes the instances across the Spot Instance pools. If the allocation strategy is <code>capacity-optimized</code>, EC2 Fleet launches instances from Spot Instance pools with optimal capacity for the number of instances that are launching.</p> <p>To scale down your EC2 Fleet, decrease its target capacity. First, the EC2 Fleet cancels any open requests that exceed the new target capacity. You can request that the EC2 Fleet terminate Spot Instances until the size of the fleet no longer exceeds the new target capacity. If the allocation strategy is <code>lowest-price</code>, the EC2 Fleet terminates the instances with the highest price per unit. If the allocation strategy is <code>capacity-optimized</code>, the EC2 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 EC2 Fleet terminates instances across the Spot Instance pools. Alternatively, you can request that the EC2 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 EC2 Fleet for now, but will use it again later, you can set the target capacity to 0.</p>

    Args:
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        excess_capacity_termination_policy: <p>Indicates whether running instances should be terminated if the total target capacity of the EC2 Fleet is decreased below the current size of the EC2 Fleet.</p> <p>Supported only for fleets of type <code>maintain</code>.</p>
        launch_template_configs: <p>The launch template and overrides.</p>
        fleet_id: <p>The ID of the EC2 Fleet.</p>
        target_capacity_specification: <p>The size of the EC2 Fleet.</p>
        context: <p>Reserved.</p>

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

    def _handler(
        req: "OperationRequest[capo_ec2.types.modify_fleet_request.ModifyFleetRequest]",
    ) -> OperationResponse["capo_ec2.types.modify_fleet_result.ModifyFleetResult"]:
        import capo_ec2._operations.amazon_ec2.modify_fleet

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

    def _redact_input(
        input_: "capo_ec2.types.modify_fleet_request.ModifyFleetRequest",
    ) -> dict[str, Any]:
        import capo_ec2.types.modify_fleet_request

        return capo_ec2.types.modify_fleet_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("ModifyFleet", redact_input=_redact_input),
    )
    input_: capo_ec2.types.modify_fleet_request.ModifyFleetRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if excess_capacity_termination_policy is not None:
        input_["excess_capacity_termination_policy"] = (
            excess_capacity_termination_policy
        )
    if launch_template_configs is not None:
        input_["launch_template_configs"] = launch_template_configs
    if fleet_id is not None:
        input_["fleet_id"] = fleet_id
    if target_capacity_specification is not None:
        input_["target_capacity_specification"] = target_capacity_specification
    if context is not None:
        input_["context"] = context

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