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.
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.
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.
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.
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:
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 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):
-
Google Cloud serverless product pages
-
Cloud SDK and
gcloud
product pages- Cloud SDK
- Cloud SDK installation
gcloud
CLI (command-line interface)gcloud
cheatsheet
-
Cloud build-relevant product pages
-
Google AI/ML API product pages
- Cloud Translation home page
- Cloud Translation documentation
- Cloud Translation Python client library (v3 for 3.x)
- Cloud Translation Python client library (v2 for 2.x)
- Translation API pricing page
- All Cloud AI/ML "building block" APIs
- Google ML Kit (Cloud AI/ML API subset for mobile)
- Google ML Kit Translation API
-
Other Google Cloud documentation
-
External links