Integrating Amazon EC2 in Java via NetBeans IDE

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);
            System.out.println(result.getDataAsString());
        } 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.

Comments:

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?

Posted by guest on March 01, 2015 at 03:30 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« July 2015
SunMonTueWedThuFriSat
   
4
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
 
       
Today