public static void main(String[] args) throws Exception {

        System.out.println("===========================================");
        System.out.println("Welcome to the AWS Java SDK!");
        System.out.println("===========================================");


        /*
         * Amazon EC2
         *
         * The AWS EC2 client allows you to create, delete, and administer
         * instances programmatically.
         *
         * In this sample, we use an EC2 client to submit a Spot request,
         * wait for it to reach the active state, and then cancel and terminate
         * the associated instance.
         */
        try {
            // Setup the helper object that will perform all of the API calls.
            Requests requests = new Requests("t1.micro","ami-8c1fece5","0.03","GettingStartedGroup");

            // Submit all of the requests.
            requests.submitRequests();

            // Create the list of tags we want to create and tag any associated requests.
            ArrayList<Tag> tags = new ArrayList<Tag>();
            tags.add(new Tag("keyname1","value1"));
            requests.tagRequests(tags);

            // Initialize the timer to now.
            Calendar startTimer = Calendar.getInstance();
            Calendar nowTimer = null;

            // Loop through all of the requests until all bids are in the active state
            // (or at least not in the open state).
            do
            {
                // Sleep for 60 seconds.
                Thread.sleep(SLEEP_CYCLE);

                // Initialize the timer to now, and then subtract 15 minutes, so we can
                // compare to see if we have exceeded 15 minutes compared to the startTime.
                nowTimer = Calendar.getInstance();
                nowTimer.add(Calendar.MINUTE, -15);
            } while (requests.areAnyOpen() && !nowTimer.after(startTimer));

            // If we couldn't launch Spot within the timeout period, then we should launch an On-Demand
            // Instance.
            if (nowTimer.after(startTimer)) {
                // Cancel all requests because we timed out.
                requests.cleanup();

                // Launch On-Demand instances instead
                requests.launchOnDemand();
            }

            // Tag any created instances.
            requests.tagInstances(tags);

            // Cancel all requests and terminate all running instances.
            requests.cleanup();
        } catch (AmazonServiceException ase) {
            // Write out any exceptions that may have occurred.
            System.out.println("Caught Exception: " + ase.getMessage());
            System.out.println("Reponse Status Code: " + ase.getStatusCode());
            System.out.println("Error Code: " + ase.getErrorCode());
            System.out.println("Request ID: " + ase.getRequestId());
        }
    }
Welcome to your new AWS Java SDK based project!

This class is meant as a starting point for your console-based application that
makes one or more calls to the AWS services supported by the Java SDK, such as EC2,
SimpleDB, and S3.

In order to use the services in this sample, you need:

 - A valid Amazon Web Services account. You can register for AWS at:
      https://aws-portal.amazon.com/gp/aws/developer/registration/index.html

 - Your account's Access Key ID and Secret Access Key:
      http://aws.amazon.com/security-credentials

 - A subscription to Amazon EC2. You can sign up for EC2 at:
      http://aws.amazon.com/ec2/
src/samples/AmazonEC2SpotInstances-Advanced/GettingStartedApp.java