API Builder

Deploy an API Builder container to Google Cloud Run

How to deploy an API Builder container to Google Cloud Run

In this blog post we will see how we can easily deploy an API Builder project using Google Cloud Run. This is useful for developers that don’t or won’t have access to Axway Amplify Runtime Services (ARS) which is currently deprecated and will be discontinued effective September 1, 2022. While not free, it is an economical and straight forward solution for hosting API Builder container images.

For this blog post, you will need familiarity and access to the following:

You will also need a working and tested API Builder project.

We will describe the steps from start to finish, and when we are done we will have an API deployed in Google Cloud Run that can be publicly accessed over the internet. Most of the work involved is in setting up CLI’s (which is a one time task) and getting an API Builder Docker image into the Google Container Registry. Creating the Google Cloud Run service is actually quite quick and easy.

Log into Google Cloud and create an application

  • Start at https://cloud.google.com/run
  • Create a new project by clicking on the Project picker in the header and click NEW PROJECT (e.g. APIB API) and note the Project ID (e.g. apib-api) as we’ll need it to tag the docker image later

  • Switch to the new project
  • Go to the Container Registry (search for Container Registry in the search bar) and click the ENABLE button to enable Google Container Registry API’s for your new project

Install and configure the gcloud CLI:

Push API Builder Docker image into Google Container Registry

We need to get our API Builder Docker image into the Google Container Registry (GCR) in order to create our Cloud Run Service. I used the Stock Watchlist API Builder API described here.

There are a couple of ways to do this:

I used Cloud Build since I am running on an M1 (ARM) Silicon MacBook Air and I got a “Container failed to start” error when I started my Cloud Run service after using the Docker CLI to push my image. I checked the Troubleshoot Cloud Run issues guide and noticed issues with ARM based machines.

From inside the API Builder project, execute the following two gcloud CLI commands to use Cloud Build to push your API Builder Docker container to GCR:

gcloud config set project apib-api
gcloud builds submit --tag gcr.io/apib-api/watchlist

Note that apib-api is the Project ID of my Google Cloud project and watchlist is the name of my API Builder project. The tag needs to have the form: gcr.io/<PROJECT ID>/<ANY NAME>

Create Google Cloud Run service

Now that we have our Docker image in the Google Container Registry, we can create our service.

  • Switch back to Google Cloud Run
  • Click on CREATE SERVICE
  • Select the image we just uploaded

  • Leave everything at the default except for “Set Authentication”. I set that to “Allow unauthenticated invocations” since I want the API to be public
  • Expand the “Container, Variables & Secrets, Connections, Security” section and leave the CONTAINER section at it’s default values
  • Click on VARIABLES & SECRETS in order to set the any API Builder environment variables
  • Recall that I used the Stock Watchlist API for this example, and it needs an API_KEY and YAHOO_FINANCE_APIKEY to be set. Use the + ADD VARIABLE button to add these two environment variables (or whatever environment variables your API Builder project uses)
  • Click CREATE to create the service
  • After about 2 minutes your service will be ready
  • You can see the URL in the screen shot above. You can use this to construct your API call as follows:
curl 'https://watchlist-uiqcoo2via-uc.a.run.app/api/watchlist?stocklist=aapl,txn' --header 'apikey: 123456789'

with response:

[
  {
    "symbol": "AAPL",
    "lastPrice": 149.64,
    "change": 5.8600006
  },
  {
    "symbol": "TXN",
    "lastPrice": 177.97,
    "change": 3.8399963
  }
]

You can click the EDIT & DEPLOY NEW REVISION button to make changes to any of the settings or to modify environment variables and re-deploy.

Click on the METRICS tab to see metrics related to API traffic.

Summary

Google Cloud Run offers a simple way to deploy API Builder Docker images. In this blog post we worked through the steps required to publish your API Builder API to Google Cloud Run and test it and monitor it.

To learn how to deploy an API Builder container using AWS Fargate, check out this blog post.

Need help with API Builder? Extend your skills with Axway University.