Amazon AWS SDK Betriebsanweisung Seite 61

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 73
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 60
50
if (anyOpen)
{
// Wait for the requests to go active.
Console.WriteLine("Requests still in open state, will retry in 60
seconds.");
55 Thread.Sleep((int)TimeSpan.FromMinutes(1).TotalMilliseconds);
}
} while (anyOpen);
If you just ran the code up to this point, your Spot Instance Request would complete—or possibly fail with
an error. For the purposes of this tutorial, we'll add some code that cleans up the requests after all of
them have transitioned out of the open state.
Step 5: Cleaning up Your Spot Requests and In-
stances
The final step is to clean up our requests and instances. It is important to both cancel any outstanding
requests and terminate any instances. Just canceling your requests will not terminate your instances,
which means that you will continue to pay for them. If you terminate your instances, your Spot Requests
may be canceled, but there are some scenarios—such as if you use persistent bids—where terminating
your instances is not sufficient to stop your request from being re-fulfilled. Therefore, it is a best practice
to both cancel any active bids and terminate any running instances.
The following code demonstrates how to cancel your requests.
1 try
{
// Cancel requests.
CancelSpotInstanceRequestsRequest cancelRequest = new CancelSpotInstan
ceRequestsRequest();
5
foreach (SpotInstanceRequest spotInstanceRequest in requestResult.Re
questSpotInstancesResult.SpotInstanceRequest)
{
cancelRequest.SpotInstanceRequestId.Add(spotInstanceRequest.SpotIn
stanceRequestId);
}
10
ec2.CancelSpotInstanceRequests(cancelRequest);
}
catch (AmazonEC2Exception e)
{
15 // Write out any exceptions that may have occurred.
Console.WriteLine("Error cancelling instances");
Console.WriteLine("Caught Exception: " + e.Message);
Console.WriteLine("Reponse Status Code: " + e.StatusCode);
Console.WriteLine("Error Code: " + e.ErrorCode);
20 Console.WriteLine("Request ID: " + e.RequestId);
}
}
To terminate any outstanding instances, we use the instanceIds array, which we populated with the instance
IDs of those instances that transitioned to the active state. We terminate these instances by assigning
Version v2.0.0
57
AWS SDK for .NET Developer Guide
Step 5: Cleaning up Your Spot Requests and Instances
Seitenansicht 60
1 2 ... 56 57 58 59 60 61 62 63 64 65 66 ... 72 73

Kommentare zu diesen Handbüchern

Keine Kommentare