Skip to content

Latest commit

 

History

History
 
 

cloud

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Nebulous serverless app demonstrating use of Google Cloud APIs

Featuring the Cloud Translation API

Description

This is the code repo for a set of codelab tutorials highlighting a "nebulous" sample app demonstrating how to access Google Cloud APIs from one of our serverless platforms. There are Python and Node.js versions of this app available.

Inspiration and implementation

This code sample was inspired by a user's suboptimal experience trying to create a simple App Engine app using a Cloud API. It was also inspired by a colleague's blog post showing a similar Node.js example "drifting" between GCP serverless platforms.

This app shows developers how to use the Cloud Translation API, the API for Google Translate, and one of GCP's AI/ML "building block" APIs. Such APIs are backed by pre-trained machine learning models, allowing developers with little or no background in AI/ML to leverage machine learning with only API calls. The application implements a mini Google Translate "MVP" (minimally-viable product) web service.

Authentication and authorization: service account credentials (local deployments only)

Google Cloud compute platforms feature default service account credentials which are used for these app deployments. However, such credentials are not available when running locally, so users will need to create a service account key-pair then download the credentials JSON file when prompted. You can typically call it anything you like, but the sample apps use credentials.json. When deploying to the cloud however, please "delete" these credentials so you don't upload that file to the cloud.

Check out the documentation for service accounts and public/private key/pairs as well as the authentication in production page for more information.

Cost

While the Translation API does not explicitly list a free quota on the "Always Free" tier page, its pricing page indicates a certain number of translated characters as a free monthly quota applied as a credit, so long as you stay within that limit, you should not incur any additional charges.

Enable Google Cloud services used

Once you have a billing account, you can enable the services/APIs for each product used. Go to the Cloud console pages for each respective Cloud product used and enable the service:

  1. App Engine
  2. Cloud Functions
  3. Cloud Run
  4. Cloud Translation

Alternatively, you use the gcloud CLI (command-line interface) available from the Cloud SDK. Review the Cloud SDK install instructions if needed. New users should also reference the gcloud cheatsheet.

Enable all 4 services with this one gcloud command: gcloud services enable translate.googleapis.com run.googleapis.com cloudfunctions.googleapis.com appengine.googleapis.com

The application itself

The app consists of a simple web page prompting the user for a phrase to translate from English to Spanish. The translated results along with the original phrase are presented along with an empty form for a follow-up translation if desired.

This is what the app looks like after completing one translation (Cloud Run version):

app screenshot

References

  1. Google Cloud serverless product pages

  2. Cloud SDK and gcloud product pages

  3. Cloud build-relevant product pages

  4. Google AI/ML API product pages

  5. Other Google Cloud documentation

  6. External links