Operating WSO2 Amazon EC2 Cloud instances from command line

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Chamara Silva
  • 8 Jan, 2010

Introduction

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 https://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 

   [email protected]:~$ 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.