Google Cloud Tutorial · Google Cloud Basics · Lesson 4 of 27
The gcloud CLI, Console and APIs
How you work with Google Cloud: the console, the gcloud CLI, client libraries and Application Default Credentials.
Ways to use Google Cloud
- Google Cloud console: the web UI, good for exploring.
- gcloud CLI (part of the Google Cloud SDK, also preinstalled in Cloud Shell): scripting and everyday work.
- Client libraries (Python, Go, Java, Node.js…) and REST APIs for applications.
- Terraform for infrastructure you want to keep in code.
gcloud auth login # your user account
gcloud config set project acme-orders-dev # default project for commands
gcloud config set compute/region europe-west1
gcloud services enable run.googleapis.com # enable an API in the project
gcloud run services list
gcloud config configurations create prod # separate settings per environment
Application Default Credentials (ADC)
Client libraries find credentials automatically through ADC: on your laptop they use
gcloud auth application-default login; on Google Cloud they use the attached service account; in CI they use
Workload Identity Federation. Your code never handles keys.
Project IDs
Project IDs are 6 to 30 characters: lowercase letters, digits and hyphens, starting with a letter and not ending with
a hyphen. They're global and permanent, so choose a naming scheme early (<company>-<app>-<env>).
import re
PATTERN = re.compile(r"^[a-z][a-z0-9-]{4,28}[a-z0-9]$")
for project_id in ["acme-orders-prod", "Acme-Orders", "orders", "acme-orders-", "1acme-dev",
"acme-a-very-long-project-name-prod"]:
ok = bool(PATTERN.match(project_id))
print(f"{project_id:38} {'valid' if ok else 'invalid'}")
Output
acme-orders-prod valid Acme-Orders invalid orders valid acme-orders- invalid 1acme-dev invalid acme-a-very-long-project-name-prod invalid
Test yourself
How do Google Cloud client libraries running on Cloud Run usually get credentials?
From a JSON key in the container imageFrom the service account attached to the service, through Application Default CredentialsFrom the developer's gcloud loginThey don't need credentials
Show answer
Answer: From the service account attached to the service, through Application Default Credentials
ADC picks up the attached service account automatically; no keys are needed.