Disruptive Technologies Disruptive Developers

Integrating with Google Cloud

This article will show you how to use a Data Connector to integrate with Google Cloud by forwarding events to a Cloud Function.


Before you begin

  1. You need to have at least Project Administrator level access to a project in Studio.

  2. You need an account on Google Cloud Platform, which is available with a 12 month free trial.


Create a Cloud Function

  1. Go to the Google Cloud Platform Console.

  2. Open the menu in the top-left corner, scroll down to the Compute section and select Cloud Functions.

    If prompted, press Enable API.

  3. Click Create function.

    In the new view, leave most the defaults, but change the code in the Inline editor to

     exports.helloWorld = (req, res) => {
     console.log("%j", req.body)
        
     /* Add further integration code here */
        
     res.status(200).send();
     };
    
  4. Scroll down, press Create and wait for it to deploy.

    A green check-mark next to the name means your Cloud Function is now deployed.

  5. Open the new Cloud Function by clicking on its name in the list.

  6. Switch to the Trigger tab and save the URL for later.


Create a Data Connector

  1. Go to Studio.

  2. Navigate to the project you want to integrate with.

  3. Open the Data Connector view for the project via the menu on the left.

  4. Click Create new.

  5. Set the Name to “Google Cloud”.

  6. Take the URL for the Cloud Function, saved previously, and enter this into Endpoint URL.

  7. Set the Data Connector to only send the Touch, Temperature and ObjectPresent events.

  8. Leave everything by default and click SAVE NEW DATA CONNECTOR.

N.B. Verify Secret: For production code it is recommended to use the Data Connector “secret” to sign each request and to verify the origin in the receiving code. See, Verify Secret.


Test the integration

To confirm that integration is up and running, we will both look at the Data Connector metrics in Studio and the Google Cloud Platform log.

Before proceeding, make sure your sensors has sent some data by pressing them a few times so that the Data Connector and the Cloud Function has run at least once.

Data Connector metrics in Studio

Navigate back to the Data Connector that you created previously in Studio.

At the top of the page, you will find how many times your new Data Connector has been run.

The Success count shows the number of times the Cloud Function has been called and returned HTTP status 200 OK the last 24h.

The Error count shows how many times it has returned an error code or timed out.

Cloud Function log in Google Cloud

Go back to the list of Cloud Function in the Google Cloud Platform Console.

Click on the button and View Logs.

Either click on the “play” or “refresh” button and expand one of the log entries.

Here we can clearly see that the sensor events are now flowing from the Data Connector to the Cloud Function.


Success!

This simple integration is easy to set up and maintain, as Google Cloud Platform takes care of all the details surrounding how the function is run. It also scales incredibly well, as a new Cloud Function will be run for each event sent by the Data Connector.


Next steps

The next steps is to replace the Add further integration code here with code to forward the events into any of Google’s vast selection of databases, event buses, stream processing or machine-learning tools.

See: