Monday, April 29, 2013

Deploying and Running WSO2 API Manager 1.3.1 in an Amazon EC2 instanace

This post is a quick guide on how to deploy WSO2 API Manager 1.3.1 in an AWS EC2 instance and running operations on it. You can also run API Manager behind an Elastic Load Balancer (ELB) in EC2 instance. The configuration procedure is same as described below, except the public DNS address to be used is the DNS of the ELB in that case.

Requirements: Amazon Web Services account
                        WSO2 API Manager 1.3.1


1. If you still don't have an AWS account create one as given here. In the account creation process you will need to specify a password and you will be given a Access Key ID and a Secret  Access Key which will be needed later for you to connect to your AWS EC2 instance.

2. Using your credentials log in to AWS Management Console and open Amazon EC2 console.

https://console.aws.amazon.com/ec2/

3. Create a new Linux instance by selecting "Launch Instance". Create your new instance by following the steps given in this guide.
In doing this choose ' Ubuntu Server 12.04' as the Amazon Machine Image (AMI) type and 'M1 Medium' as the instance type. Specify relevant key-pair or create a new one. If you create a new key-pair, download this into your computer and make sure you remember where it is located in your machine. (You need this later in this post!)




4. Once you finish creating an instance you can see it in the running instances list in the console. if you click on it you will see more information about the new instance.

4. Now let's connect to this instance  and deploy our Am 1.3.1 pack here. 
  • Goto the location where you key-pair is located. Now we are going to connect to our Ubuntu server instance in EC2 using SSH. 

  • Find the Public DNS address of your instance. In my case this is 'ec2-00-000-000-00.compute-1.amazonaws.com' (Note that i have changed the digits in my EC2 instance DNS here).

  • Enter the following command in the terminal.

  • ssh -i ishara.pem ubuntu@ec2-00-000-000-000.compute-1.amazonaws.com

  • In here  'isarap.pem' is the keypair file that was downloaded when creating the EC2 instance.
    ec2-00-000-000-000.compute-1.amazonaws.com is the public DNS address of your instance.

  • Most probably there will be 'permission denied' error when you try this the first time. This is because there is more permission given for your keypair file when it is created. We need to make to more access restricted. For that use,

  • chmod 400 ishara.pem

  • After that when you try to SSH you will be able to successfully connect to your instance in AWS EC2.You will now see the following message which means you are now connected.
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-36-virtual x86_64)

* Documentation: https://help.ubuntu.com/

System information as of Mon Apr 29 17:48:41 UTC 2013 
System load: 0.08                 Processes: 59 
Usage of /: 32.9% of 7.87GB Users logged in: 0 
Memory usage: 32%             IP address for eth0: 10.202.151.238 
Swap usage: 0% 

Graph this data and manage this system at https://landscape.canonical.com/ Get cloud support with Ubuntu Advantage Cloud Guest http://www.ubuntu.com/business/services/cloud 

Use Juju to deploy your cloud instances and workloads. https://juju.ubuntu.com/#cloud-precise 

Last login: Mon Apr 29 07:03:15 2013 from 203.143.18.194 
ubuntu@ip-10-202-151-238:~$
.........................................................................................................


5. As now you are logged into ubuntu instance, consider this as a normal scenario where you work on your local computer. Make a new directory in EC2 instance as apim/ and copy API Manager 1.3.1.zip pack into this EC2 instance.

ubuntu@ip-10-202-151-238:~$ pwd
/home/ubuntu

ubuntu@ip-10-202-151-238:~$  mkdir apim/


Open another terminal and enter command,
scp -i ishara.pem wso2am-1.3.1.zip ubuntu@ec2-00-000-000-00.compute-1.amazonaws.com:/home/ubuntu/apim

This will be copying Am 1.3.1 distribution files into the apim/ directory in EC2 instance. Similarly copy JDK 1.6 pack as you needs it to run the API Manager in EC2. 

6. Unzip both distributions now. If 'zip' is not installed you will first need to install it. Edit the .bashrc in /home/ubuntu directory and add the path to your JDK ad JAVA_HOME in it.

7. Unzip the API Manager 1.3.1 pack too. In order to start the API Manager server in an outside location we need to configure carbon.xml and api-manager.xml files in AM_HOME/repository/conf directory . The following guide explains how to do this in detail.

API Manager User Guide: http://dist2.wso2.org/products/api-manager/1.3.0/APIManager-GettingStarted-v1.3.0.pdf 

In addition find the following entries in api-manager.xml and specify the values given below.

<KeyValidatorClientType>WSClient</KeyValidatorClientType>
<EnableThriftServer>false</EnableThriftServer>  
 


..........................................................................................................
Note: You need to install 'curl' in EC2 instance to follow the steps in this guide. If there are issues occurs when trying with,

pubname=$(curl http://169.254.169.254/latest/meta­data/public­hostname 2>/dev/null);
export JAVA_OPTS=­Damazon.pub.hostname=$pubname


In that case remove the above lines from .bashrc file and manually enter the 'EC2 instance public DNS url' into the places described in the configuration. 

For example instead of adding,

<HostName>${amazon.pub.hostname}</HostName> in carbom.xml file you can enter as 
<HostName>ec2-00-000-000-00.compute-1.amazonaws.com</HostName>

...............................................................................................................................

 
8. When all these configurations are over, start API Manager from /home/ubuntu/apim/wso2am-1.3.1/bin. Point your browser to,

https://ec2-00-000-00-00.compute-1.amazonaws.com:9443/carbon/ 



9. The WSO2 Admin Console for API Manager will be started! You are running AM 1.3.1 in AWS EC2 now :)  


No comments:

Post a Comment