Geertjan's Blog

  • June 8, 2014

Integrating Amazon EC2 in Java via NetBeans IDE

Geertjan Wielenga
Product Manager

Next, having looked at how to integrate from Java with Amazon Associates and Amazon S3, let's take a look at Amazon EC2, the elastic compute cloud which provides remote computing services. I started by launching an instance of Ubuntu Server 14.04 on Amazon EC2, which looks a bit like this in the on-line AWS Management Console, though I whitened out most of the details:

Now that I have at least one running instance available on Amazon EC2, it makes sense to use the services that are integrated into NetBeans IDE: 

I created a new application with one class, named "AmazonEC2Demo". Then I dragged the "describeInstances" service that you see above, with the mouse, into the class. Then the IDE automatically created all the other files you see below, i.e., 4 Java classes and one properties file:

In the properties file, register the access ID and secret keys. These are read by the other generated Java classes. Signing and authentication are done automatically by the code that is generated, i.e., there's nothing generic you need to do and you can immediately begin working on your domain-specific code.

Finally, you're now able to rewrite the code in "AmazonEC2Demo" to connect to Amazon EC2 and obtain information about your running instance:

public class AmazonEC2Demo {
public static void main(String[] args) {
String instanceId1 = "i-something";
RestResponse result;
try {
result = AmazonEC2Service.describeInstances(instanceId1);
} catch (IOException ex) {
Logger.getLogger(AmazonEC2Demo.class.getName()).log(Level.SEVERE, null, ex);

From the above, you'll receive a chunk of XML with data about the running instance, it's name, status, dates, etc. In other words, you're now ready to integrate Amazon EC2 features directly into the applications you're writing, without very much work to get started. Within about 5 minutes, you're working on your business logic, rather than on the generic code that anyone needs when integrating with Amazon EC2.

Join the discussion

Comments ( 1 )
  • guest Sunday, March 1, 2015

    Hi Geertjan!

    Thank you for your post. So, I have a question.

    I've a Netbeans 8 client installed on my localhost and I have a webservice running on Amazon EC2 server.

    I need to connect my netbeans for php (localhost) to Amazon source (PHP), that is possible?

    Can you send me a connection example? How should I configure my NetBeans to connect to Amazon AC2 Server?

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.