Skip to content

cancel_spot_fleet_requests async

cancel_spot_fleet_requests(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    spot_fleet_request_ids: Optional[SpotFleetRequestIdList] = None,
    terminate_instances: Optional[Boolean] = None,
) -> CancelSpotFleetRequestsResponse

Cancels the specified Spot Fleet requests.

After you cancel a Spot Fleet request, the Spot Fleet launches no new instances.

You must also specify whether a canceled Spot Fleet request should terminate its instances. If you choose to terminate the instances, the Spot Fleet request enters the cancelled_terminating state. Otherwise, the Spot Fleet request enters the cancelled_running state and the instances continue to run until they are interrupted or you terminate them manually.

Terminating an instance is permanent and irreversible.

After you terminate an instance, you can no longer connect to it, and it can't be recovered. All attached Amazon EBS volumes that are configured to be deleted on termination are also permanently deleted and can't be recovered. All data stored on instance store volumes is permanently lost. For more information, see How instance termination works.

Before you terminate an instance, ensure that you have backed up all data that you need to retain after the termination to persistent storage.

Restrictions

  • You can delete up to 100 fleets in a single request. If you exceed the specified number, no fleets are deleted.

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.

  • spot_fleet_request_ids (Optional[SpotFleetRequestIdList], default: None ) –

    The IDs of the Spot Fleet requests.

    Constraint: You can specify up to 100 IDs in a single request.

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

    Indicates whether to terminate the associated instances when the Spot Fleet request is canceled. The default is to terminate the instances.

    To let the instances continue to run after the Spot Fleet request is canceled, specify no-terminate-instances.

Raises:

Examples:

To cancel a Spot fleet request This example cancels the specified Spot fleet request and terminates its associated Spot Instances.

>>> await client.cancel_spot_fleet_requests(spot_fleet_request_ids=['sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE'], terminate_instances=True)
To cancel a Spot fleet request without terminating its Spot Instances
This example cancels the specified Spot fleet request without terminating its associated Spot Instances.
>>> await client.cancel_spot_fleet_requests(spot_fleet_request_ids=['sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE'], terminate_instances=False)
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def cancel_spot_fleet_requests(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    spot_fleet_request_ids: Optional[
        "capo_ec2.types.spot_fleet_request_id_list.SpotFleetRequestIdList"
    ] = None,
    terminate_instances: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.cancel_spot_fleet_requests_response.CancelSpotFleetRequestsResponse":
    """<p>Cancels the specified Spot Fleet requests.</p> <p>After you cancel a Spot Fleet request, the Spot Fleet launches no new instances.</p> <p>You must also specify whether a canceled Spot Fleet request should terminate its instances. If you choose to terminate the instances, the Spot Fleet request enters the <code>cancelled_terminating</code> state. Otherwise, the Spot Fleet request enters the <code>cancelled_running</code> state and the instances continue to run until they are interrupted or you terminate them manually.</p> <important> <p> <b>Terminating an instance is permanent and irreversible.</b> </p> <p>After you terminate an instance, you can no longer connect to it, and it can't be recovered. All attached Amazon EBS volumes that are configured to be deleted on termination are also permanently deleted and can't be recovered. All data stored on instance store volumes is permanently lost. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/how-ec2-instance-termination-works.html"> How instance termination works</a>.</p> <p>Before you terminate an instance, ensure that you have backed up all data that you need to retain after the termination to persistent storage.</p> </important> <p class="title"> <b>Restrictions</b> </p> <ul> <li> <p>You can delete up to 100 fleets in a single request. If you exceed the specified number, no fleets are deleted.</p> </li> </ul>

    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>
        spot_fleet_request_ids: <p>The IDs of the Spot Fleet requests.</p> <p>Constraint: You can specify up to 100 IDs in a single request.</p>
        terminate_instances: <p>Indicates whether to terminate the associated instances when the Spot Fleet request is canceled. The default is to terminate the instances.</p> <p>To let the instances continue to run after the Spot Fleet request is canceled, specify <code>no-terminate-instances</code>.</p>

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

    Examples:
        To cancel a Spot fleet request
        This example cancels the specified Spot fleet request and terminates its associated Spot Instances.

        >>> await client.cancel_spot_fleet_requests(spot_fleet_request_ids=['sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE'], terminate_instances=True)
        To cancel a Spot fleet request without terminating its Spot Instances
        This example cancels the specified Spot fleet request without terminating its associated Spot Instances.

        >>> await client.cancel_spot_fleet_requests(spot_fleet_request_ids=['sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE'], terminate_instances=False)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.cancel_spot_fleet_requests_request.CancelSpotFleetRequestsRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.cancel_spot_fleet_requests_response.CancelSpotFleetRequestsResponse"
    ]:
        import capo_ec2._operations.amazon_ec2.cancel_spot_fleet_requests

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.cancel_spot_fleet_requests.async_cancel_spot_fleet_requests(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CancelSpotFleetRequests")
    )
    input_: capo_ec2.types.cancel_spot_fleet_requests_request.CancelSpotFleetRequestsRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if spot_fleet_request_ids is not None:
        input_["spot_fleet_request_ids"] = spot_fleet_request_ids
    if terminate_instances is not None:
        input_["terminate_instances"] = terminate_instances

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output