Cancels the specified Capacity Reservation, releases the reserved capacity, and changes the Capacity Reservation's state to cancelled.
You can cancel a Capacity Reservation that is in the following states:
-
assessing
-
scheduled — requires a cancellation quote. Use CreateCapacityReservationCancellationQuote to generate a quote, then pass the quote ID with ApplyCancellationCharges set to commitment-wind-down. The cancellation charge depends on how close the reservation is to its start date.
-
active and there is no commitment duration or the commitment duration has elapsed.
-
active during the commitment duration — requires a cancellation quote. Use CreateCapacityReservationCancellationQuote to generate a quote, then pass the quote ID with ApplyCancellationCharges set to commitment-wind-down. The Capacity Reservation transitions to cancelling while charges are applied.
-
delayed — the commitment duration is waived, so no cancellation charge applies.
You can't modify or cancel a Capacity Block. For more information, see Capacity Blocks for ML.
Instances running in the reserved capacity continue running until you stop them. Stopped instances that target the Capacity Reservation can no longer launch. Modify these instances to either target a different Capacity Reservation, launch On-Demand Instance capacity, or run in any open Capacity Reservation that has matching attributes and sufficient capacity.
Parameters:
-
capacity_reservation_id
(Optional[CapacityReservationId], default:
None
)
–
The ID of the Capacity Reservation to be cancelled.
-
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.
-
apply_cancellation_charges
(Optional[ApplyCancellationCharges], default:
None
)
–
Specifies the cancellation charge type to apply when cancelling a future-dated Capacity Reservation during its commitment duration. Possible values include commitment-wind-down, which continues billing for the remaining commitment duration without delivering capacity.
-
quote_id
(Optional[CapacityReservationCancellationQuoteId], default:
None
)
–
The ID of the cancellation quote to use for the cancellation. You can generate a cancellation quote by using the CreateCapacityReservationCancellationQuote action. The cancellation quote must be in an active state.
Raises:
Source code in docs_src/capo_ec2/_services/ec2.py
| def cancel_capacity_reservation(
self,
*,
config_overrides: Optional[EC2ClientConfig] = None,
capacity_reservation_id: Optional[
"capo_ec2.types.capacity_reservation_id.CapacityReservationId"
] = None,
dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
apply_cancellation_charges: Optional[
"capo_ec2.types.apply_cancellation_charges.ApplyCancellationCharges"
] = None,
quote_id: Optional[
"capo_ec2.types.capacity_reservation_cancellation_quote_id.CapacityReservationCancellationQuoteId"
] = None,
) -> "capo_ec2.types.cancel_capacity_reservation_result.CancelCapacityReservationResult":
"""<p>Cancels the specified Capacity Reservation, releases the reserved capacity, and changes the Capacity Reservation's state to <code>cancelled</code>.</p> <p>You can cancel a Capacity Reservation that is in the following states:</p> <ul> <li> <p> <code>assessing</code> </p> </li> <li> <p> <code>scheduled</code> — requires a cancellation quote. Use <code>CreateCapacityReservationCancellationQuote</code> to generate a quote, then pass the quote ID with <code>ApplyCancellationCharges</code> set to <code>commitment-wind-down</code>. The cancellation charge depends on how close the reservation is to its start date.</p> </li> <li> <p> <code>active</code> and there is no commitment duration or the commitment duration has elapsed.</p> </li> <li> <p> <code>active</code> during the commitment duration — requires a cancellation quote. Use <code>CreateCapacityReservationCancellationQuote</code> to generate a quote, then pass the quote ID with <code>ApplyCancellationCharges</code> set to <code>commitment-wind-down</code>. The Capacity Reservation transitions to <code>cancelling</code> while charges are applied.</p> </li> <li> <p> <code>delayed</code> — the commitment duration is waived, so no cancellation charge applies.</p> </li> </ul> <note> <p>You can't modify or cancel a Capacity Block. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-capacity-blocks.html">Capacity Blocks for ML</a>.</p> </note> <p>Instances running in the reserved capacity continue running until you stop them. Stopped instances that target the Capacity Reservation can no longer launch. Modify these instances to either target a different Capacity Reservation, launch On-Demand Instance capacity, or run in any open Capacity Reservation that has matching attributes and sufficient capacity.</p>
Args:
capacity_reservation_id: <p>The ID of the Capacity Reservation to be cancelled.</p>
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>
apply_cancellation_charges: <p>Specifies the cancellation charge type to apply when cancelling a future-dated Capacity Reservation during its commitment duration. Possible values include <code>commitment-wind-down</code>, which continues billing for the remaining commitment duration without delivering capacity.</p>
quote_id: <p>The ID of the cancellation quote to use for the cancellation. You can generate a cancellation quote by using the <code>CreateCapacityReservationCancellationQuote</code> action. The cancellation quote must be in an <code>active</code> state.</p>
Raises:
capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
"""
def _handler(
req: "OperationRequest[capo_ec2.types.cancel_capacity_reservation_request.CancelCapacityReservationRequest]",
) -> OperationResponse[
"capo_ec2.types.cancel_capacity_reservation_result.CancelCapacityReservationResult"
]:
import capo_ec2._operations.amazon_ec2.cancel_capacity_reservation
output, http_response = (
capo_ec2._operations.amazon_ec2.cancel_capacity_reservation.cancel_capacity_reservation(
req.options, req.input
)
)
return OperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("CancelCapacityReservation")
)
input_: capo_ec2.types.cancel_capacity_reservation_request.CancelCapacityReservationRequest = {}
if capacity_reservation_id is not None:
input_["capacity_reservation_id"] = capacity_reservation_id
if dry_run is not None:
input_["dry_run"] = dry_run
if apply_cancellation_charges is not None:
input_["apply_cancellation_charges"] = apply_cancellation_charges
if quote_id is not None:
input_["quote_id"] = quote_id
response = execute_pipeline(
OperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
response.response.close()
return response.output
|