Monday, October 5, 2015

Launch EC2 instance and check status via AWS SDK for Java

Apart from the AWS web console, AWS functionalities are also accessible via Command Line Interface (CLI), APIs or SDK. This blog post summarizes how to launch an EC2 instance and to test its running status via AWS SDK for Java.

The programming environment:
Eclipse Java EE IDE for Web Developers.
Version: Luna Release (4.4.0)
Install the AWS toolkit according to the instructions listed on http://aws.amazon.com/eclipse/.

Credentials are important for authentication. 
AmazonEC2Client is the basis to call various APIs. (Since in this project I used the instance for load generation, I named it as runLoadGeneratorRequest/Result) To launch an instance, the key is the .runInstances() method. We can configure the RunInstancesRequest object as needed. 

AmazonEC2Client is the basis to call various APIs. (Since in this project I used the instance for load generation, I named it as runLoadGeneratorRequest/Result) To launch an instance, the key is the .runInstances() method. We can configure the RunInstancesRequest object as needed. 

The “loadGeneratorID” variable is used for identification.
Various tasks could not be performed unless the instance is in “Running” status and the initializing process could take long.
Code below demonstrates how to test if the instance specified by the “loadGeneratorID” is ready.

No comments:

Post a Comment