Operating WSO2 Amazon EC2 Cloud instances from command line

In this tutorial, Chamara Silva, Senior Software Engineer (Quality Assurance) at WSO2 guides you on how you can work with Amazon AMI instances from command line instead of using any GUI interfaces like Elasticfox. Cloud computing is relatively a new technology that gives small to mid-size companies the computing power needed to compete in the market place without having to burden themselves with the high cost of purchasing additional computers, storage and all the extra equipment that is usually needed.

Date: Fri, 8th Jan, 2010
Level: Introductory
Reads: 1664 Comments: 1 | Login or register to post comments
Chamara Silva
Senior Software Engineer - QA
WSO2 Inc.
chamara's picture

Introduction

It’s secure, fast, scalable, global in nature, powerful, stable and green. In short, it brings high end computing power and storage to every business with minimal upfront investment.

Thinking about the possibilities that this can bring also makes me think about the fear and hesitancy that will come along with it initially. We need to face the fact that we’re turning over a physical server to something that, in a lot of people's mind, is far less tangible because they can’t see, touch or feel it. I know it goes without saying that most company executives don’t really walk into their Data Centers on a regular basis but, they seem to feel secure knowing that they could if they wanted to do so.

Since this technology can really be best described as utility computing, a good analogy would be something similar to the electric company. Everyone has electricity in their homes and office but very few people are physically generating that power on-site. It is only a matter of time before someone came up with the idea of applying the utility concept to computing power. This may sound pretty flippant but, in all reality the programming behind the Cloud is absolutely amazing.

Not only can single servers be put into the Cloud for a company but, the ability to place their entire Data Centers is possible and exists right now. Can you imagine eliminating the Data Center or a fish bowl in your office space and putting that real estate to use in a more efficient manner? It’s mind boggling how much money could potentially be saved with this technology.

Now the Windows / Linux / UNIX administrators can focus their attention on making sure things are running smoothly, accounts are created and software is being deployed and not to worry about figuring out and replacing failed hardware. All that together adds up to some pretty powerful solutions that are now available to everyone.

WSO2's products are now exposed in to the cloud computing technology. WSO2 SOA products now available as private and public cloud deployments. Currently WSO2 cloud products support "Amazon EC2" as a public cloud platform and VMware, Linux KVM as a private cloud platform. In this tutorial I am going to explain how you can setup and operate WSO2 Amazon EC2 Cloud products.

Key Features
  • Self-service deployment and zero configuration
  • Automatically scale up or down as loads vary
  • A cost-effective, pay-as-you-go fee structure covering basic production support

 

Applies To

WSO2 Web Application Server 3.1.1
WSO2 Enterprise Service Bus 2.1.1
WSO2 Governance Registry 3.0.1
WSO2 Identity Server 2.0.1
WSO2 Mashup Server 2.0.1

Contents

  1. Getting Private Key Files
  2. Setup Amazon-APT Tools
  3. Creating Key Pair
  4. Start AMI Instance
  5. Summary

 

Getting Private Key Files from Amazon


Step 1: Now you need Amazon EC2 account to operate Amazon instances. Before you start please create your own account at http://aws.amazon.com/.

Step 2: Once you have created an Amazon account you will get a couple of PEM-endosed x509 certificate and private key files as 

    cert-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem (A PEM encoded signed X.509 certificate)

    pk-HKZYKTAIG2ECMXYIBH3HXV4ZBZQ55CLO.pem (An unencrypted, PEM encoded RSA private key that corresponds to the X.509 certificate above)

Step 3: Now download that .pem files.

 

Setup Amazon API Tools

Amazon API Tools package serves as the client interface of the Amazon EC2 web services. To control our web servics we are using this interface. Following are the steps for setting up Amazon API Tools package.

Step 4: download Amazon-API tools package.

Step 5: Create a folder called "ami" in your machine, copy and extract "ec2-api-tools.zip".

Step 6: Set "EC2_HOME"environment variable by locating ec2-api-tools folder.

 If you are in Linux open a terminal or .bashrc  and insert EC2_HOME,

Syntax -

   export EC2_HOME=<directorypath/ami/ec2-api-tools>   

 Example -

   export EC2_HOME=/home/chamara/ami/ec2-api-tools>   

 If you are in Windows set EC2_HOME as a enviroment variable.

Syntax - 

   set EC2_HOME=<folderpath/ami/ec2-api-tools>    

Example - 

   set EC2_HOME=c://chamara/ami/ec2-api-tools

   

Step 7: Now add ec2-api-tools/bin folder path to your path variable. (See the above screenshot)

Step 8: Create a folder named ".ec2" and copy cert and PK .pem files in to that.(We have already downloaded this)

Step 9: Now you have to create couple of invirenment variables by locating .pem files. 

 If you are in Linux open a terminal or .bashrc  and insert EC2_PRIVATE_KEY & EC2_CERT,

Syntax -

   export EC2_PRIVATE_KEY=<folderpath/.ec2/pk-********.pem> 
export EC2_CERT=<folderpath/.ec2/cert-*******.pem>

 Example -

   export EC2_PRIVATE_KEY=/home/chamara/.ec2/pk-********.pem>        export EC2_CERT=/home/chamara/.ec2/cert-*******.pem>

 If you are in Windows set EC2_PRIVATE_KEY & EC2_CERT as enviroment variables.

Syntax - 

   set EC2_PRIVATE_KEY=<folderpath/.ec2/pk-********.pem> 
set
EC2_CERT=<folderpath/.ec2/cert-*******.pem>

Example -

   set EC2_PRIVATE_KEY=c//chamara/.ec2/pk-********.pem
set
EC2_CERT=c://chamara/.ec2/cert-*******.pem

 

   

Step 10: To check this open a terminal or command prompt and traverse to .ec2 folder and type "ec2-describe-images". You will see all the available AMI images in your terminal if you have configured successfully.

 

Creating Keypair

Step 11:  Now you have to create or own your key pair. To create that key pair in command prompt/terminal goto the .ec2 folder and type "ec2-add-keypair yourname-keypair"

     Example 

   chamara@chamara-laptop:~$ ec2-add-keypair chamara-keypair

     Now you can see your private key in your terminal. 

   

Step 12: Now create a file called "id_rsa-yourname-keypair" in ec2 directory.(Enter same name (key pair name)  what you added in Step 11.)

Step 13: Copy private key list in your terminal (point 11) from " -----BEGIN RSA PRIVATE KEY-----" to "-----END RSA PRIVATE KEY-----" in to the "id_rsa-yourname-keypair" file.

Step 14: If you are on linux give permission to that file.

      In terminal, type 

   chmod 600 id_rsa-yourname-keypair

Step 15: Now complete all the configuration and you should be able to run any AMI instances from command line.

 

Start AMI Instance

Step 16: If you want to run 32 bit AMI instance,

      in terminal, go to the .ec2 folder and type 

 ec2-run-instances ami-ID -k yourname-keypair

Step 17: If you want to run 64 bit instance you need to type,

 ec2-run-instances ami-ID -k yourname-keypair --instance-type m1.large

    

    

Step 18: If you want to see the status of the running instance you need to type this command in terminal.

      "ec2-describe-instance instance-id"  (You can see when you start the instance using ami-id. Instance id start with i-1212 etc.)

    

For a example if you want to run 32 bit WSAS instance you have to get AMI-ID from the wso2.com page.

WSAS ID  = ami-80bd5fe9

Start WSAS instance like,

have
 ec2-run-instance ami-80bd5fe9 -k chamara-keypair

Step 19: After few seconds type "ec2-describe-instance instance-id" in terminal. You will see ec2 domain name like "ec2-174-129-171-196.compute-1.amazonaws.com". This is the unique url for your running instance.

 

Step 20: In your browser, type "https://ec2-174-129-171-196.compute-1.amazonaws.com/carbon" url and you will see WSAS management console finally.

Step 21: If you want to terminate instance you to type,

 ec2-terminate-instances instance-id

Summary

     This tutorial explains how you can work with Amazon AMI instances from command line instead of using any GUI interfaces like Elasticfox. This tutorial mainly points out a way of using WSO2 Carbon based AMI products such as WSO2 Web Services Application Server, WSO2 Enterprise Service Bus, WSO2 Governance Registry, WSO2 Mashup Server, WSO2 Identity Server etc. from command line.   

Author
Chamara Silva. Senior Software Engineer (Quality Assurance). WSO2 Inc. chamara AT wso2 DOT com.

 

 

stagedramay.gmail.com's picture

Nice Tutorial

thanks for sharing i hope it could work well

http://stagedramay.com

Hot Topic
Hot
Topic

Google Gadgets are a nice way to develop user interfaces for distributed services. The fact that they can be hosted anywhere over a network, not necessarily in the very portal server they eventually run in makes them re-usable and allows users to quickly...

Mini Banners
WSO2Con 2010
Latest Webinar
In this webinar we'll share the range of concerns we've heard from the industry, and survey some of the new and sometimes subtle types of lock-in associated with cloud technologies.
Wednesday, 8 September, 10.00 AM (PDT)