Google Cloud Functions and WSO2 API Manager

Google Cloud Functions and WSO2 API Manager

WSO2 API Manager is a fully open-source full lifecycle API Management solution that can be run anywhere

This article was inspired by a use case where a serverless function running on Google Cloud was to be fronted via WSO2 API Manager. Since Google Cloud Functions can be deployed in multiple ways, it's a pretty straight-forward approach to setup WSO2 API Manager to trigger a cloud function via HTTP.

We will now take a look at what is needed to set up a Google Cloud Function and then front it with WSO2 API Manager to leverage its benefits. Some features of the WSO2 API Manager are presented here.

Setting up a Google Cloud Function as a REST backend

Google Cloud Functions support the following language runtime environments. For this example, the backend is going to be a set of cloud functions that will be triggered via HTTP and be executed on a NodeJS 8 runtime.

There are multiple ways to deploy a Google Cloud Function. There is no recommended way but the method followed here is via the gcloud-cli from a local machine.

To deploy from a machine, the gcloud cli is required.

Once the gcloud-cli is installed take a look at this to set up a basic cloud function by extracting the steps necessary to set up a node app on your local machine. Since this cloud function is written in NodeJS, Node will need to be installed. This will help to set up a basic cloud function and give a brief idea of how the HTTP trigger works.

After this is completed the following command can be run to deploy the cloud function with an HTTP trigger. The region has to be one of the regions where Cloud Functions are available.

gcloud functions deploy <function-name> --runtime nodejs8 --region <region> --trigger-http --entry-point app

Example: gcloud functions deploy first-function --runtime nodejs8 --region asia-east2 --trigger-http --entry-point app

The gcloud-cli will prepare the function and deploy it. If there is no error you will be provided with the URL needed to trigger the cloud function

Setting up the WSO2 API Manager to trigger previously deployed cloud function

To set up the WSO2 API Manager follow the instructions available in the Quick Start Guide here. The API Manager should now be accessible at https://localhost:9443. The WSO2 API Manager is a product built up of multiple components: API Publisher, Developer Portal, Gateway, Traffic Manager, Key Manager and Analytics (Optional). This allows for various deployment patterns to enable independent scaling for components such as the Gateway over UI components.

Once the server is up and running continue to creating and publishing an API. We will need to access the API Publisher portal (https://localhost:9443/publisher) which is where APIs are created and access with default credentials (admin:admin).

No alt text provided for this image

We can now proceed to create an API.

No alt text provided for this image

In the next step in the endpoint details, we now have to use the URL that was generated by the gcloud-cli previously for the endpoint option. We can then proceed with the next steps and publish the API.

Why the WSO2 API Manager

The previous sections were very straight forward in terms of setting up the WSO2 API Manager and getting it to expose a Google Cloud Function via a REST endpoint. Lets now take a look at some of the benefits of fronting a serverless function with the WSO2 API Manager.

Keep your business logic abstract

As with microservices serverless functions can each do their share of business logic. By having an API Gateway it is possible to change the function at any time without the top layer API users noticing any change

Secure your serverless functions

WSO2 API Manager can prevent control access to APIs. This allows an easy implementation of authentication and authorization layer over the APIs that in turn proxy the requests to the cloud functions

Map a WebSocket to a serverless function, which cannot normally be done (An edge case but the requirement may rise)

WSO2 API Manager is a fully open-source solution that allows us to customize should we require. If there is a need to proxy a web socket message to a cloud function in the form of an HTTP request it is possible to do so. An implementation of this will be discussed in a future article.

Any other benefits that could arise from using an API Management solution such as the WSO2 API Manager

Message enrichment, traffic management, monetization, providing end-users an easy portal to browse APIs are just scratching the surface of what an API Management solution can do.

As a starting point setting up the WSO2 API Manager and exposing a Google Cloud Function is pretty easy. Once they are done it is possible to explore some of the benefits of fronting a serverless function with it. The documentation is available here. In the next few articles let's look at how we can play around with the API Manager and also at more complex customizations as we go on.

To view or add a comment, sign in

Others also viewed

Explore content categories