
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Enable the Cloud AI Companion API and grant the necessary IAM roles
/ 20
Build the web app
/ 40
Explain and run the query
/ 40
A day in the life of a Google Cloud developer typically involves the use of multiple Google Cloud products and services. These products enable the developer to develop, test, deploy, and manage applications in the cloud. With assistance from Gemini, a developer can become more productive when using Google Cloud's products by using Gemini's interactive chat, code assistance, and embedded integrations.
In this lab, you use Gemini to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that contains development tools. It offers a persistent 5-GB home directory and runs on Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources. gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab completion.
Click the Activate Cloud Shell button () at the top right of the console.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are also authenticated, and the project is set to your PROJECT_ID.
(Output)
(Example output)
(Output)
(Example output)
Sign in to the Google Cloud console with your lab credentials, and open the Cloud Shell terminal window.
To set your project ID, in Cloud Shell, run the following commands:
Store the signed-in Google user account in an environment variable:
Enable the Cloud AI Companion API for Gemini:
To use Gemini, grant the necessary IAM roles to your Google Cloud Qwiklabs user account:
Adding these roles lets the user use Gemini assistance.
To verify the objective, click Check my progress.
This lab uses the Cymbal Superstore
grocery web app. In subsequent tasks of this lab, you use Gemini to develop and deploy a new feature in this app. In this task, you build the frontend and backend components of this app.
Execute the following commands and the next two subtasks in Cloud Shell.
To run the Docker credential helper, run the following command:
If asked to continue, type Y.
Download the cymbal-superstore
application code:
The web app backend implements an inventory API that is used by the frontend to fetch and update products.
To build the backend application container image, run the following commands:
Push the backend container image to Artifact Registry:
To deploy the backend as a service on Cloud Run, run the following command:
Copy the value of the Service URL
that is displayed in the output of the gcloud run deploy
command.
Build the frontend by executing the commands in your Cloud Shell terminal.
Update the frontend code to connect to your backend Cloud Run endpoint:
a. In the Cloud Shell menubar, click Open Editor.
b. In the editor View menu, click Toggle hidden files.
c. In the folder list in Explorer, select cymbal-superstore
.
d. Expand the frontend
folder, and select the file .env.production
.
e. In the file, replace the value of REACT_APP_INVENTORY_API_URL
by pasting the value of your Cloud Run backend service endpoint URL that you copied earlier.
To build the frontend, click Open Terminal, and then run the following commands in Cloud Shell:
To upload the frontend web app to Cloud Storage, run the following command:
Open a tab in your browser, and then navigate to the following URL:
The web app displays the home page of the Cymbal Superstore.
Click New Arrivals.
You should see a mock frontend page with placeholder products. This is expected, as you will implement the backend Inventory API code to serve the new products page in subsequent tasks of this lab.
To verify the objective, click Check my progress.
Let's now use Gemini to add functionality to our web app backend.
In this task, you prompt Gemini for code completion to implement the /newproducts
endpoint in the app.
/newproducts
endpointIn the Cloud Shell editor, open the file backend/index.ts
.
In the index.ts
source code file, scroll to line 91 where you see the placeholder comment for the /newproducts
endpoint:
Replace the placeholder comment with the following Gemini prompt:
To prompt Gemini to generate the function code, select the entire comment, and then click the bulb ().
In the More Actions menu, select Gemini: Generate code.
Hover over the generated code, and in the Gemini toolbar, click Accept.
Gemini populates the function code for the /newproducts
endpoint.
The generated code should be similar to the following:
If your generated code does not look equivalent to the example in the previous step, replace the code in index.ts
with the code from the previous step.
Let's test the /newproducts
backend endpoint locally using npm
.
Before running the backend, you must set the PORT environment variable.
In the Cloud Shell editor menubar, select View > Command Palette....
In the command palette, type user settings json, and from the list, select Preferences: Open User Settings (JSON).
Update the JSON object by adding the following attribute:
comma
to the end of the previous attribute in the JSON object.After adding the attribute, the attributes object should be similar to this:
In the Cloud Shell terminal, authenticate the application to access Firestore:
Follow the instructions by clicking the link to authenticate your Google Cloud account and copy/paste the authorization code where requested.
To start the backend server, run the following commands:
The backend inventory API server starts and is ready when it shows the following text:
/newproducts
endpointIn the Cloud Shell terminal menu bar, click + to open a new terminal.
To invoke the API endpoint, run the following command:
The command responds with an error:
In the original terminal window view the exception trace that is logged from the backend.
From the trace, it seems that the root cause of the exception is:
In the Cloud Shell editor, open the backend/index.ts
file.
To open the Gemini Code Assist chat window, in the menu bar of the code editor, click Gemini Code Assist Chat.
In the Ask Gemini prompt, type the following prompt, and then click Send ():
Gemini responds with the explanation of this error and suggestions to fix it. Here's part of an example response:
Gemini also provides a solution to fix the error.
To fix this error, you will only use a single inequality filter.
In the backend/index.ts
file, to remove the quantity
filter, delete the following code from the /newproducts
handler:
By deleting this code, there is now only one inequality filter that checks the timestamp, products with a quantity of 0 will not be filtered from the API response.
To remove products that have a quantity of 0, wrap the code in products.forEach()
with the following if
statement:
After you wrap the code with the if statement, the products.forEach()
code should look similar to:
Save the backend/index.ts
file.
To restart the backend API server, in a terminal, run the following commands:
Switch to the other bash
terminal, and then run the curl command again:
The backend API responds with a json
array that contains a list of recently added products.
In the original Cloud Shell terminal, type Control+C to exit the application.
Follow the previous steps to rebuild the updated backend service container image, push the image to the registry, and redeploy the backend service to Cloud Run. The steps are repeated here for convenience.
In Cloud Shell, open a new terminal, or use the terminal that is already open.
To build the backend container image, push it to the repository, and deploy the backend service on Cloud Run, run the following commands:
Open a tab in your browser, and then navigate to the following URL:
The web app displays the home page of the Cymbal Superstore.
Click New Arrivals.
The page should display products that are returned in the response from the /newproducts
endpoint, which you implemented in the previous task.
In this task, you write a test for the new products API in the backend with help from Gemini.
In the Cloud Shell editor, open the file backend/index.test.ts
.
To open the Gemini Code Assist chat window, in the menu bar of the code editor, click Gemini Code Assist Chat.
To prompt Gemini to help you write a test for the GET endpoint /newproducts
, type the prompt below, and click Send ():
Gemini responds with the generated test code. Copy and paste the describe
code block for the /newproducts
endpoint into the backend/index.test.ts
file.
To execute the tests, in the Cloud Shell terminal run the following commands:
As indicated by the output of the test
command, all tests are executed and pass.
In this task, you get help from Gemini to upload data to a table in BigQuery, and construct a query that fetches data from that table.
In the Google Cloud console Navigation menu (), select BigQuery.
In the BigQuery Explorer pane, expand cymbal_sales
dataset, and then select the table cymbalsalestable
.
To open the Gemini Cloud Assist chat window, in the Google Cloud console top menu, click Open Gemini (), and then click Start Chatting.
For the Gemini prompt, type the text below, and then click Send ():
View the response from Gemini. The response contains the bq load
command which can be run to upload data from Cloud Storage to BigQuery.
In Cloud Shell, run the following command:
In the BigQuery UI, click Refresh ().
View the table's schema.
Click Query.
Replace the default query with:
To run the query, click Run.
In the Results tab, view the results of the query that contains data from the table. The table contains sample weekly aggregate sales data of product sales from the Cymbal Superstore web application.
Let's use Gemini to help generate a query for weekly sales total amounts.
To prompt Gemini to generate a query for the sales of the following week of Aug 12, in the same Query field below the previously entered query, leave a blank line, and click Gemini () on the left side of the blank line.
In the Generate SQL with Gemini dialog, type:
Click Generate.
Wait for Gemini to generate the query. Then, click Insert.
Select the query, right-click, and choose Explain Current Selection. You can also click the Gemini magic pencil that appears in the left margin.
An explanation of the SQL query is provided in the Cloud Assist chat window.
To run the query, click Run.
The query results are displayed in the Results tab at the bottom of the page.
To verify the objective, click Check my progress.
A Spanner instance and database containing sample sales transaction data has been pre-provisioned for this lab.
In this task, you use Gemini to generate a SQL query to fetch data from the transactions
database.
In the Google Cloud console menu, under Databases, click Spanner.
Click the link to open the Spanner instance Cymbal Superstore Transactions
.
To open the database, click transactions-db.
In the left pane, under Database, click Spanner Studio.
Click to select the Untitled query tab.
In the Query box, click Generate SQL with Gemini (), type SELECT, and then click Generate.
Wait for Gemini to provide SQL suggestions.
To accept the suggestions, click Insert.
If present, delete the WHERE
clause from the SQL query.
To execute the query, click Run.
View the results from the query.
You can use Gemini to help operate and manage your services on Google Cloud. In this task, you follow instructions from Gemini to view logs for the inventory backend that runs on Cloud Run.
To open the Cloud Assist chat window in the Google Cloud console, in the top menu bar, click Gemini Cloud Assist chat ().
For the Gemini prompt, type the prompt below, and then click Send ():
To view the logs for the Cloud Run service inventory
, follow the instructions in Gemini's response.
In this lab you learned how to:
When you have completed your lab, click End Lab. Qwiklabs removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one