Google Cloud Functions provide a streamlined method for running a simple micro-service leveraging custom functions as well as SDKs for any Google service that can be imported into your script. Currently, node.js is the only non-beta language you can build scripts in.
Permissions
Before you setup Google Cloud Functions in your G Suite domain, first provide the account of a developer with the appropriate permissions, identified in the attached screen.
Enable The SDKs You Need
G Suite has a number of features exposed to their API by importing SDKs into projects. As an example, the Admin SDK provides us with endpoints and classes that make developing micro services to perform actions in the G Suite admin portal easier. In this section we’ll import that SDK, although the tasks for importing other SDKs is similar.
To get started, open the Google Cloud Platform using the button in the upper left hand corner and click on APIs and Services (the names of these buttons change over time).
TheClick on the Enable APIs and Services button in the dashboard.
Under Credentials, provide the appropriate credentials for the app you’re importing the SDK into.
Search for Admin SDK in the search dialog.
Click Admin SDK, made by Google.
Click Enable.
Once enabled, you’ll need to create a service account for your function to communicate with.
Setup A Service Account
Service accounts give you a JWT, useful to authenticate from a Google Cloud Function back to an instance of the GSuite Admin portal endpoints. To setup a Service account, go to “IAM & admin” using the button in the upper left hand corner.
Click on Services Accounts.
Provide a project name and a location (if your organization uses locations, otherwise leave that set to No Organization.
Create Your Google Cloud Function
The Google Cloud Function is the microservice that you can then call. This might be sending some json from an app to perform a task from an app, or sending a webhook to the function to perform an action. To get started with functions, click Cloud Function at the bottom of the Google Cloud Platform dashboard.
If functions aren’t enabled, click Enable Billing.
If necessary, click UPGRADE.
The function api will also need to be enabled; if so, click Enable API.
Once all of this is done, you should have a button that says Create function. Click that and then you’ll be able to provide settings for the function.
Settings include the following:
- Name: How the function is called in the admin panel.
- Memory allocated: How much memory the function can consume.
- Trigger: Most will use HTTP for our purposes.
- URL: The URL you use to call the function.
- Source: The code (typically node.js) that is run.
Note: The package.json allows for us to leverage this function in a multi-tenant fashion.
Once enabled, you can hit the endpoint. If there’s no header parameters you need to send, that could be as simple as:
curl https://us-central1-alpine-canto-231018.cloudfunctions.net/test-function