Cloud Shell¶
Cloud shell contains GCP’s software development kit (SDK) or helper libraries. This massively simplifies interacting with services such as APIs.
The cloud shell environment sits on a VM spun up in the cloud and accessible by your GCP account. It gives command line access to your projects and their resources according to your IAM settings.
Unleash the command line interface (CLI) with VMs on your console.
Function Trees¶
Cloud Shell’s commands are split by function into:
- gsutil
- storage
- bigQuery
- gcloud
- platform
- products
- services (data analytics, ML, networking, APIs)
The gcloud command starts with the group that it manages, e.g. to create an instance using Compute Engine:
Basic Commands¶
Try this from console
gcloud config set account `ACCOUNT`
There are a ton of great tools on this bash- + Google SDK-hosting machine. Here are just a few commands to have a play around with:
- list the active account name with:
gcloud auth list
- list project ID with:
gcloud config list project
- list organisation ID with:
Of course, similar information may be pulled using the Compute Engine command:
gcloud compute project-info describe
- or see all your accessible projects (this will list the properties in your active SDK configuration):
gcloud config list
- pick up the project number directly from gcloud
gcloud projects list
A really useful tool is saving environment variables on that VM machine using bash to allow your commands to be written in a kinda DRY manner.
- set an environment variable; Hipster Shop version:
export HIPSTER_VERSION=1.0.0
Notice that here you are using bash, rather than the gcloud command. NB the SDK does not include bash. It is the Linux VM that is providing bash.
I like this - is there more?¶
The big G has, of course, documented the lot
But here are a few more firm favorites:
display all your functions
gcloud functions list
display all available zones
gcloud compute zones list
display all available zones in selected region
gcloud compute zones list | grep us-central1
Rather than administer each VM directly, you may configure them all through settings.
configure default zone
gcloud config set compute/zone us-central
launch new VM
gcloud compute instances create "my-new-vm"
--machine-type "n1-standard-1"
--image-project "debian-cloud"
--image "debian-9-stretch-v20170918" \
--subnet "default"
launch a more useful VM
Being able to talk to the world through your own wee tunnel is very useful. my-new-vm could be a lot more fun (and less safe)!
gcloud config set compute/zone us-central
gcloud compute instances create "lamp-1-vm"
--machine-type "n1-standard-2"
--image-project "debian-cloud"
--image "debian-9-stretch-v20170918" \
--subnet "default"
Allow HTTP traffic with
gcloud compute firewall-rules create lamp-1-vm
--allow tcp:80
close cloud shell
exit
SDK¶
GCP’s SDK has client libraries for:
- Java
- Pthon
- Node.js
- Ruby
- Go
- .NET
This means that it can be a useful environment in itself. For example, I am using Python’s Sphinx to generate this static site from a PC by typing commands in the GCP SDK installed locally on my machine.