User guide
} catch (AmazonServiceException e) {
// Write out any exceptions that may have occurred.
System.out.println("Error canceling instances");
System.out.println("Caught Exception: " + e.getMessage());
245 System.out.println("Reponse Status Code: " + e.getStatusCode());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Request ID: " + e.getRequestId());
}
250 //===========================================================//
//=============== Terminating any Instances =================//
//===========================================================//
try {
// Terminate instances.
255 TerminateInstancesRequest terminateRequest = new TerminateInstances
Request(instanceIds);
ec2.terminateInstances(terminateRequest);
} catch (AmazonServiceException e) {
// Write out any exceptions that may have occurred.
System.out.println("Error terminating instances");
260 System.out.println("Caught Exception: " + e.getMessage());
System.out.println("Reponse Status Code: " + e.getStatusCode());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Request ID: " + e.getRequestId());
}
265 } // main
}
Tags are a simple first step toward making it easier to manage your own cluster of instances. To read
more about tagging Amazon EC2 resources, go to Using Tags in the Amazon EC2 User Guide for Linux
Instances.
Bringing It All Together
To bring this all together, we provide a more object-oriented approach that combines the steps we showed
in this tutorial into one easy to use class. We instantiate a class called Requests that performs these
actions. We also create a GettingStartedApp class, which has a main method where we perform the
high level function calls.
The complete source code is available for download at GitHub.
Congratulations! You've completed the Advanced Request Features tutorial for developing Spot Instance
software with the AWS SDK for Java.
Getting Temporary AWS Credentials with SWS
STS
You can use the AWS Security Token Service (AWS STS) to get temporary, limited-privilege credentials
that can be used to access AWS services.
There are three steps involved in using AWS STS:
1. Activate a region (optional).
Version v1.0.0
61
AWS SDK for Java Developer Guide
Getting Temporary AWS Credentials with SWS STS