forked from aws/aws-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGettingStartedApp.java
More file actions
90 lines (79 loc) · 3.21 KB
/
GettingStartedApp.java
File metadata and controls
90 lines (79 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import com.amazonaws.AmazonServiceException;
/**
* 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/
*
*/
public class GettingStartedApp {
private static final long SLEEP_CYCLE = 60000;
/*
* Important: Be sure to fill in your AWS access credentials in the
* AwsCredentials.properties file before you try to run this
* sample.
* http://aws.amazon.com/security-credentials
*/
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();
// Submit all of the requests.
requests.submitRequests();
// 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);
} while (requests.areAnyOpen());
// 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());
}
}
}