
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 Cloud Run API
/ 25
Create a PostgreSQL instance
/ 25
Deploy a public service
/ 25
Test the application
/ 25
Cloud SQL automatically ensures your databases are reliable, secure, and scalable so that your business continues to run without disruption. Cloud SQL automates all your backups, replication, encryption patches, and capacity increases—while ensuring greater than 99.95% availability, anywhere in the world.
Lab content is based on resolving a customer use case through the use of serverless infrastructure. The lab features three high level sections that resolve a technical problem:
These labs are based on intermediate knowledge of Google Cloud. While the steps required are covered in the content, it would be helpful to have familiarity with any of the following products:
In this lab, you learn to:
This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Scenario: In this lab, you will help the development team at Critter Junction investigate Cloud SQL. The company runs its infrastructure on Google Cloud and is very interested in experimenting with serverless.
The dev team would like to explore how to use Cloud SQL and Cloud Run.
The team at Critter Junction have a web application that requires a data store. Cloud SQL appears to be a good solution, but the team does not have any experience with this product.
The team would also like a solution that does not introduce any additional complexity to their systems. Historically they have used PostgreSQL so would like to use that if it's an option. Now you know a bit more about Critter Junction and the issues they face, try and prioritize the key criteria for a solution.
The team at Critter Junction are keen to define a solution that can be implemented quickly. They explain their current event processing as represented by the diagram illustrated below:
A series of meetings with stakeholders are held to ascertain the key priorities. The results of which are shown below:
Ref |
User Story |
1 |
As a development lead, I want to focus on frontend development, so my team can maintain velocity. |
2 |
As a data lead, I want to focus on existing skill sets, so that developers minimize learning new products. |
3 |
As an ops lead, I want to ensure service accounts are used, so product authentication is handled internally. |
From a discussion with the team leads, the following high level tasks are defined:
Ref |
Definition of Done |
1 |
Deploy the website using Cloud Run |
2 |
Use Cloud SQL with Postgres |
3 |
Use a Service Account with Cloud SQL with minimize IAM permissions |
The following high level architecture diagram summaries the minimal viable product they wish to investigate.
In the proposed solution, Cloud SQL will be used to handle the data tier.
Critter Junction has a website that they would like to integrate with Cloud SQL. To build an MVP the following activities are required:
Set up some environment variables to make the provisioning process more flexible
Click Check my progress below to check your lab progress.
Google Cloud SQL is a fully managed relational database service for MySQL, PostgreSQL, and SQL Server.
Cloud SQL key features:
Feature |
Description |
Fully Managed |
Cloud SQL automatically ensures your databases are reliable, secure, and scalable so that your business continues to run without disruption. Cloud SQL automates all your backups, replication, encryption patches, and capacity increases—while ensuring greater than 99.95% availability, anywhere in the world. |
Integrated |
Access Cloud SQL instances from just about any application. Easily connect from App Engine, Compute Engine, Google Kubernetes Engine, and your workstation. Open up analytics possibilities by using BigQuery to directly query your Cloud SQL databases. |
Reliable |
Easily configure replication and backups to protect your data. Go further by enabling automatic failover to make your database highly available. Your data is automatically encrypted, and Cloud SQL is SSAE 16, ISO 27001, and PCI DSS compliant and supports HIPAA compliance. |
Easy Migration to Cloud SQL |
Database Migration Service (DMS) makes it easy to migrate your production databases to Cloud SQL with minimal downtime. This serverless offering eliminates the manual hassle of provisioning, managing, and monitoring migration-specific resources. DMS leverages the native replication capabilities of MySQL and PostgreSQL to maximize the fidelity and reliability of your migration. And it's available at no additional charge for native like-to-like migrations to Cloud SQL. |
Now you understand what Cloud SQL provides, it is time to configure our project to use it.
As you now know Cloud SQL requires a number of configuration options. Learn how to configure a PostgreSQL database in the following section.
Create a new Cloud SQL instance and add the following values.
In the Google Cloud Console, on the Navigation menu (), click SQL.
Click Create instance.
For Choose your database engine, select Choose PostgreSQL.
Create a PostgreSQL instance with the following values:
Field |
Value |
Instance ID |
poll-database |
Password |
secretpassword |
Choose a Cloud SQL edition |
Enterprise |
Database version |
PostgreSQL 13 |
Region |
|
Zone |
Single Zone |
Great work!
The Cloud SQL database has been created successfully. In the next section populate the database with the required table and data.
Click Check my progress below to check your lab progress.
Enter the Cloud SQL password when requested (i.e. "secretpassword").
Connect to the database:
votes
table:totals
table:The Cloud SQL database has been successfully populated with the data required for the application. In the next section deploy a Cloud Run service to connect to the database.
To provision the tabspaces service the application expects some environment variables to be set.
Environment Value |
Description |
DB_USER |
Name of the database user |
DB_PASS |
Password for the database user |
DB_NAME |
Name of the database |
CLOUD_SQL_CONNECTION_NAME |
The name given to the Cloud SQL instance |
The environment values will be passed to the application and used by the deployed application.
Deploy the Poll service on Cloud Run.
Click Check my progress below to check your lab progress.
The Poll service should look similar to below:
Click Check my progress below to check your lab progress.
Over this course of this lab, you have seen how to incorporate Cloud SQL within your Google Cloud infrastructure.
Follow the Serverless Expeditions video series to learn more about how to utilize these products within your project.
Manual Last Updated September 26, 2024
Lab Last Tested September 26, 2024
Copyright 2022 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