- Lab
- A Cloud Guru
Creating Google Cloud Firestore Collections and Documents
You are tasked with developing a small web app to track a list of famous computer scientists. You want to store the details in a NoSQL document store so that you can interact with database records as JSON documents. If this app ever needs to scale, you need the database to be strongly consistent and globally available. To achieve this, you will create a Cloud Firestore database and connect to it with a Python Flask web app that runs in the Cloud Run serverless platform.
Path Info
Table of Contents
-
Challenge
Activate Cloud Shell and the Required APIs
- From inside the GCP dashboard, load the Cloud Shell terminal. Your project should already be active in the terminal (highlighted in yellow), but if it isn't, enter the following code using your project ID, which is located next to the Google Cloud Platform title at the top of the GCP dashboard:
gcloud config set project <YOUR_PROJECT_ID>
- In the Cloud Shell terminal, using
gcloud
, activate the following APIs, which are required for this lab:run.googleapis.com
cloudbuild.googleapis.com
containerregistry.googleapis.com
- Configure these settings for Cloud Run using
gcloud config
:- Set the region to
us-east1
- Set the platform to
managed
- Set the region to
- From inside the GCP dashboard, load the Cloud Shell terminal. Your project should already be active in the terminal (highlighted in yellow), but if it isn't, enter the following code using your project ID, which is located next to the Google Cloud Platform title at the top of the GCP dashboard:
-
Challenge
Create a Firestore Collection and Documents
For this objective, we need to:
- Create a new Firestore database that is set to Native Mode and located in us-east1.
- Start a collection with the Collection ID of
compscientists
. - Create the first document with the following information set on three lines:
- Line one:
- Field name:
first
- Field type:
string
- Field value:
Ada
- Field name:
- Line two:
- Field name:
last
- Field type:
string
- Field value:
Lovelace
- Field name:
- Line three:
- Field name:
birthyear
- Field type:
number
- Field value:
1815
- Field name:
- Create a second document for
Alan Turing
, born in1912
, using the same formatting from before for Field name and Field type, and update the Filed value with his information.
-
Challenge
Deploy and Test the Flask Application
For this objective, you need your GCP project ID, which can be found next to the Google Cloud Platform title on the GCP dashboard:
- Clone the necessary
git
repo to get the Flask application code. This is our repo:https://github.com/linuxacademy/content-google-certified-pro-cloud-developer
- Change to the
flask-firestore
directory. - Build the demo app using
gcloud
,--tag
,gcr.io
, and our project ID. Make sure to place it in theflask-firestore
directory. - Deploy
flask-firestore
to Cloud Run using--image
,gcr.io
, and our project ID. Make sure it is placed in ourflask-firestore
directory without having to be authenticated. - Use the returned URL for your newly deployed app.
- Browse the URL and view the demo page listing the documents in the collection.
- Add a new computer scientist (perhaps yourself!) to the collection using the web app's form. Make sure you use proper names and a real year, as there is no exception handling in this web app.
- Check that the new document is listed both in the web app and in GCP.
- Clone the necessary
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.