Use CancelSpotFleetRequests with a CLI - Amazon Elastic Compute Cloud
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use CancelSpotFleetRequests with a CLI

The following code examples show how to use CancelSpotFleetRequests.

CLI
Amazon 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-instances

Output:

{ "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-instances

Output:

{ "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.

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 a complete list of Amazon SDK developer guides and code examples, see Create Amazon EC2 resources using an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.