There are more AWS SDK examples available in the AWS Doc SDK Examples
Use CancelSpotFleetRequests
with a CLI
The following code examples show how to use CancelSpotFleetRequests
.
- CLI
-
- AWS CLI
-
Example 1: To cancel a Spot fleet request and terminate the associated instances
The following
cancel-spot-fleet-requests
example cancels a Spot Fleet request and terminates the associated On-Demand Instances and Spot Instances.aws ec2 cancel-spot-fleet-requests \ --spot-fleet-request-ids
sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE
\ --terminate-instancesOutput:
{ "SuccessfulFleetRequests": [ { "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "CurrentSpotFleetRequestState": "cancelled_terminating", "PreviousSpotFleetRequestState": "active" } ], "UnsuccessfulFleetRequests": [] }
For more information, see Cancel a Spot Fleet request in the Amazon Elastic Compute Cloud User Guide for Linux Instances.
Example 2: To cancel a Spot fleet request without terminating the associated instances
The following
cancel-spot-fleet-requests
example cancels a Spot Fleet request without terminating the associated On-Demand Instances and Spot Instances.aws ec2 cancel-spot-fleet-requests \ --spot-fleet-request-ids
sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE
\ --no-terminate-instancesOutput:
{ "SuccessfulFleetRequests": [ { "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "CurrentSpotFleetRequestState": "cancelled_running", "PreviousSpotFleetRequestState": "active" } ], "UnsuccessfulFleetRequests": [] }
For more information, see Cancel a Spot Fleet request in the Amazon Elastic Compute Cloud User Guide for Linux Instances.
-
For API details, see CancelSpotFleetRequests
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example cancels the specified Spot fleet request and terminates the associated Spot instances.
Stop-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TerminateInstance $true
Example 2: This example cancels the specified Spot fleet request without terminating the associated Spot instances.
Stop-EC2SpotFleetRequest -SpotFleetRequestId sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE -TerminateInstance $false
-
For API details, see CancelSpotFleetRequests in AWS Tools for PowerShell Cmdlet Reference.
-