Getting started with Google Cloud Platform (GCP) is actually very easy but as with getting started with anything sometimes you just want a quick 101 of essential steps to set you on your merry way.
Note this post is to help you get up and running as quickly as possible but it does assume that you have read best practices for configuring permissions on gcp
Developing and deploying applications on GCP is arranged around projects and thus understanding how you intend to set up development and admin accees for projects is an important initial step.
The next thing to do is to sign up for a Google Cloud account via the sign up page Sign Up for Google Compute Engine
Now that you are ready to get started start a terminal session .
Now you’ve signed up download the GCloud SDK following the instructions for your OS gcloud compute
Then go through the authorisation process by typing
gcloud auth login
The GCloud SDK uses Google’s OAuth 2.0 service to authorize users and programs to access Google APIs.
Managing authentication and credentials
The GCloud SDK actually bundles the individual command line tools for each service as well as the appropriate SDK’s for each supported language . The moduarlarity is great but can be a bit confusing at first.
So what exactly do you get when you download the Google Cloud Platform SDK?
If you’re following along type the following:
gcloud components list
This gives you a list of the modules for each service
For those components you do not have installed or need an update use the command
gcloud components update component-name
so for example to update the App engine SDK for GO I would type:
gcloud components update gae-go
Next make sure you are working in the correct project
gcloud config list
to check what the currently set default project has been set to
You can set a different default project by typing
gcloud config set project YourProjectID
You can run this at anytime to reset the default project. If you are working on more than one project you will need to specify the non default project appropriately and where or when you do this depends on the comamnd.
Note: you will probably have to activate any services you need to use for a particular project by using the console, making sure you are in the project you wish to activate the service for then selecting API’s under API’s and Auth and setting the status to on for the services you want activated for the project
Each GCP product has it’s own set of commands and you need to use the appropriate set of commands to interact with the service.
See the list produced from the
gcloud components list
For example to interact with BigQuery you use bq and for Cloud Storage you use gsutil.
Below is an example showing how easy it is to get started by listing out the set of commands that I used to upload a csv file to Cloud storage usng gsutil, using bq to load the data into Bigquery, and to start querying that data.
First I created a schema as this is needed to pass to bq when creating the table
Then I uploaded my data set to cloud storage:
gsutil cp PeriodicTableDataSet.csv gs://my-periodicatable-bucket
Next I created a Big table dataset called elements
bq mk elements
Then in a single command I created a table and loaded it with my dataset
bq load elements.ptable gs://my-periodictable-bucket/PeriodicTableDataSet.csv ptable_schema.json
This returns a success status like he one below if everything okay
Waiting on bqjob_r1c83caf93cc4a0db_0000014a0057532d_1 … (27s) Current status: DONE
So Now I could start querying my data after just 3 steps (4 if you include creating the schema) once I had signed up
bq query "SELECT name, symbol from elements.ptable where Z >100"
Waiting on bqjob_r64487038b0ec017d_0000014a005b650e_1 ... (0s) Current status: DONE +----------------+--------+ | name | symbol | +----------------+--------+ | Mendelevium | Md | | Nobelium | No | | Lawrencium | Lr | | Rutherfordium | Rf | | Dubnium | Db | | Seaborgium | Sg | | Bohrium | Bh | | Hassium | Hs | | Meitnerium | Mt | | Darmstadtium | Ds | | Roentgenium | Rg | | Ununbium | Uub | | Ununtrium | Uut | | Ununquadium | Uuq | | Ununpentium | Uup | | Ununhexium | Uuh | | Ununseptium | Uus | | Ununoctium | Uuo | +----------------+--------+
Help is avaiable by typing Command –help or comamnd help
Thus for cloudstorage you would type
gsutil --help for BigQuery
So as you can see within a few minutes of setting up your account you are ready to start using the command line tools for GCP and getting immediate pay back.