How to deploy WSO2 API Manager in an AWS instance from scratch

Tharika Madurapperuma
6 min readOct 18, 2018

WSO2 API Manager is a platform for creating, managing, consuming and monitoring APIs. It employs proven SOA best practices to solve a wide range of API management challenges such as API provisioning, API governance, API security and API monitoring. It combines some of the most powerful and mature components of the WSO2’s state-of-the-art Carbon platform to deliver a smooth and end-to-end API management experience while catering to both API publisher and API consumer requirements.

For more information refer : https://wso2.com/api-management/

In this article I will guide you on how to make an all-in-one (single node) deployment of WSO2 API Manager with analytics.

What do we have?

A WSO2 API Manager distribution (APIM — 2.6.0)

A WSO2 API Manager Analytics distribution (APIM Analytics — 2.6.0)

2 AWS Ubuntu instances where no required software are installed

What do we know?

With regard to the 2 AWS instances, we only have the following information.

  • The .pem private key file to be used to connect to the 2 instances
  • The Public DNS of each instance

What are we trying to do?

We will be deploying the WSO2 API Manager distribution in one AWS Instance while deploying the WSO2 API Manager Analytics distribution in the other AWS Instance.

Then the API Manager and Analytics distributions will be connected to each other so that we can successfully view statistics of API Invocations etc.

These are the steps that we will be following in this article.

Step 1 : Push the 2 API Manager distributions to the relevant instances

Step 2 : Configure required software

Step 3 : Configure the 2 API Manager distributions for connection and analytics

Step 4 : Successfully test the setup and view statistics

Step 1

Push the 2 API Manager distributions to the relevant instances

For this purpose, we will use an FTP solution like FileZilla. We can easily transfer files from this.

In FileZilla, we need to first configure the private key file.

Go to Edit -> Preferences -> SFTP as shown in the figure below.

Add key file to FileZilla

We can then import the private key file (.pem) by clicking on “Add key file” option.

After successfully adding the key file, you can now connect to the first instance to push the WSO2 API Manager distribution.

For that, go to File -> Site Manager -> New site as shown in the figure below.

Connect to AWS instance from FileZilla

After that select “SFTP — SSH File Transfer Protocol” as the Protocol value and add the Public DNS of the first AWS instance under Host. Since this is an Ubuntu Instance, the user will be ubuntu.

Then click “Connect” to connect to the AWS instance from FileZilla.

In FileZilla, you have two windows which corresponds to the Local site (which is your local computer) and the Remote site (which is the AWS instance that we will be connecting to).

After the logs getting printed in the top of the FileZilla window shows you that the connection is successfully established, drag and drop the WSO2 API Manager distribution zip file from the Local site to the Remote site.

At the bottom of the FileZilla window, you will see the progress of the file transfer. After it is successfully completed, you can similarly transfer the WSO2 API Manager Analytics Distribution zip file to the other AWS Instance from FileZilla, following the same steps we did above.

Now you have successfully transferred the 2 zipped distributions to the relevant AWS Instances.

Step 2

Configure required software

For running the WSO2 API Manager servers we need java installed in the 2 AWS Instances. So now let’s see how this can be done.

We should SSH into the first AWS Instance using the following command. Type it in the terminal.

ssh -i /path/to/pem/file ubuntu@<public-dns-of-instance>

Replace the /path/to/pem/file and <public-dns-of-instance> with relevant values.

After successfully connecting to the instance through the terminal, check whether java is installed using the following command.

java -version

If it is not installed, let’s go ahead installing it.

Note : You can use the method that I have described here or any other method for installing Java in the AWS instance. That does not matter.

Here we will be installing oracle jdk-8u181 for 64 bit Linux.

wget — no-cookies — no-check-certificate — header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.tar.gz"

The above command will download the jdk tar ball. Now insert the below commands in order based on the downloaded tar ball.

sudo mkdir /opt/jdk

sudo tar -zxf jdk-8u181-linux-x64.tar.gz -C /opt/jdk

sudo update-alternatives — install /usr/bin/java java /opt/jdk/jdk1.8.0_181/bin/java 100

sudo update-alternatives — install /usr/bin/javac javac /opt/jdk/jdk1.8.0_181/bin/javac 100

Verify the installation using the

java -version

command.

Now we need to add the java installation to the PATH. Open the /etc/environment file. You then need to add the content as below.

The PATH variable should be appended with the following

:/opt/jdk/jdk1.8.0_181/bin

Then add the following also into the file.

JAVA_HOME=”/opt/jdk/jdk1.8.0_181"

Now you have successfully configured Java in the AWS instance.

But there is a possible error case that you might encounter.

WARN Couldn't flush system prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.

If you get an error similar to the above, execute the below commands so that you can successfully get rid of it.

mkdir -p ~/.java/.systemPrefs

mkdir ~/.java/.userPrefs

chmod -R 755 ~/.java

Now add the following line to /etc/environment file. Replace with the correct paths if required.

JAVA_OPTS=”-Djava.util.prefs.systemRoot=/home/ubuntu/.java -Djava.util.prefs.userRoot=/home/ubuntu/.java/.userPrefs”

You have to install Java 8 in both the AWS Instances.

Step 3

Configure the 2 API Manager distributions for connection and analytics

First connect to both AWS Instances and configure WSO2 API Manager and WSO2 API Manager Analytics for Analytics based on the relevant product documentation.

In this article, I will be using the default H2 database, hence no special database configurations are needed.

Then one important thing we should do is setting up the correct hostname in the API Manager server. We cannot use default localhost here because we need to allow users to access to the API Manager servers through their browsers. For that we’ll configure the Public DNS of the API Manager instance instead of localhost.

Let’s see how this can be done.

In the <API-M_HOME>/repository/conf/carbon.xml file, uncomment and change the <HostName> and <MgtHostName> to the Public DNS of the API Manager instance.

Then in <API-M_HOME>/repository/conf/api-manager.xml file, change the <StreamProcessorServerURL> and <StreamProcessorRestApiURL> to the Public DNS of the API Manager Analytics Instance.

After that, replace all occurrences of localhost with the Public DNS of the API Manager Instance in the <API-M_HOME>/repository/conf/api-manager.xml file.

Make sure that you open the relevant ports in both the instances so that they can be accessed from outside. The ports in this case means 9443, 8243, 9444 depending on your configuration. For this, you have to create specific security groups in AWS. If you are unable to access the AWS console to do it, request this from the person who gave you the instance details and the credentials to connect to the instances.

Step 4

Successfully test the setup and view statistics

Now you can start both the servers in the two instances. If required you can start the servers in the background so that even when your ssh session expires, the servers will be running.

First SSH into the Analytics Instance and execute the command below to start the server in the background from within the <API-M_ANALYTICS_HOME>/bin.

./worker.sh start

Then ssh into the API Manager Instance and execute the command below to run the server in the background from within <API-M_HOME>/bin.

./wso2server.sh start

Now you can start creating APIs, invoke them and view Analytics just like you do with a local API Manager and Analytics setup in you machine. :)

--

--