Puntos de control
Create a Bigtable instance
/ 20
Simulate streaming traffic sensor data into Pub/Sub
/ 20
Launch dataflow pipeline
/ 20
Stop streaming jobs and delete Bigtable data
/ 20
Streaming Data to Bigtable
- GSP1055
- Overview
- Setup and requirements
- Task 1. Create a Bigtable instance and table using commands
- Task 2. Simulate streaming traffic sensor data into Pub/Sub
- Task 3. Launch a Dataflow pipeline to write data from Pub/Sub into Bigtable
- Task 4. Verify streaming data loaded into Bigtable
- Task 5. Stop streaming jobs and delete Bigtable data
- Congratulations!
GSP1055
Overview
Bigtable is Google's fully managed, scalable NoSQL database service. Bigtable is ideal for storing large amounts of data in a key-value store and for use cases such as personalization, ad tech, financial tech, digital media, and Internet of Things (IoT). Bigtable supports high read and write throughput at low latency for fast access to large amounts of data for processing and analytics.
For streaming data from sensors, Bigtable can handle high writes to capture large volumes of real-time data.
In this lab, you use commands to create a Bigtable instance with a table to store simulated traffic sensor data. Then you launch a Dataflow pipeline to load the simulated streaming data from Pub/Sub into Bigtable. While the Dataflow job loads streaming data from Pub/Sub into Bigtable, you verify that the table is being successfully populated. You complete the lab by stopping the streaming job and deleting the Bigtable data.
What you'll do
In this lab, you learn how to create a Bigtable instance and table using commands and use Dataflow to load streaming data.
- Create a Bigtable instance using Google Cloud CLI (
gcloud
CLI) commands. - Create a Bigtable table with column families using Cloud Bigtable CLI (
cbt
CLI) commands. - Launch a Dataflow pipeline to read streaming data from Pub/Sub and write into Bigtable.
- Verify the streaming data loaded into Bigtable.
- Delete a Bigtable table and a Bigtable instance using commands.
Prerequisites
- Basic understanding of database concepts and terms such as instances, schemas, and keys
- Completion of the lab titled Designing and Querying Bigtable Schemas
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This 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:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
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:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
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.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Create a Bigtable instance and table using commands
To create a new table in Bigtable, you first need to create a Bigtable instance to store your table. To create a Bigtable instance, you can use the Google Cloud console, gcloud
CLI commands, or cbt
CLI commands.
In this task, you use Cloud Shell to first run gcloud
CLI commands to create a new Bigtable instance, and then run cbt
CLI commands to connect to Bigtable and create a new table.
For a review of how to access Cloud Shell, click Setup and requirements on the right-side menu of this page.
Create a Bigtable instance
- To create a new Bigtable instance, in Cloud Shell, run the following command:
This command creates a new Bigtable instance with the following properties:
Property | Value |
---|---|
Instance ID | sandiego |
Instance display name | San Diego Traffic Sensors |
Storage Type | SSD |
Cluster ID | sandiego-traffic-sensors-c1 |
Zone | |
Node scaling mode | Manual allocation |
Number of nodes | 1 |
When you receive the output message, continue to the next step.
Configure the Bigtable CLI
To connect to Bigtable using cbt
CLI commands, you first need to use Cloud Shell to update the .cbtrc
configuration file with your project ID and your Bigtable instance ID.
- To modify the
.cbtrc
file with the project ID and instance ID, run the following commands:
- To verify that you have successfully modified the
.cbtrc
file, run the following command:
The output should resemble the following:
Create a Bigtable table with column families
After you configure the .cbtrc
configuration file in Cloud Shell, you can run a simple cbt
CLI command to create a new Bigtable table with column families.
- To create a new table named current_conditions with one column family named lane, run the following command:
Click Check my progress to verify the objective.
Task 2. Simulate streaming traffic sensor data into Pub/Sub
In this task, you run a streaming data simulator from a Compute Engine virtual machine (VM) that has been created for this lab. To begin this task, you will enter commands on a VM named training-vm to set up your environment and download the necessary files for the streaming data simulator.
Connect to the VM
-
In the Google Cloud console, on the Navigation menu, click Compute Engine > VM instances.
-
Locate the line with the instance called training-vm, and under Connect, click SSH.
A terminal window for training-vm will open.
The training-vm is installing some software in the background. In the next step, you verify that setup is complete by checking the contents of the new directory.
-
To list the contents of the directory named training, run the following command:
The VM is ready for you to continue when the output of the ls
command yields the following result:
If the three scripts are not listed, wait a few minutes and try again.
Run script to simulate streaming data
- To download a code repository for use in this lab, run the following command:
- To set up the required environmental variables, run the following command:
This script sets the $DEVSHELL_PROJECT_ID
and $BUCKET
environment variables so that you do not have to manually set these variables for Project ID and Cloud Storage bucket name.
A Cloud Storage bucket was created for you during the initialization of lab resources.
- To start the streaming data simulator, run the following command:
This script reads sample data from a CSV file and publishes it to Pub/Sub. This script will send one hour of data in one minute.
Let the script continue to run in the current terminal, and continue with the next tasks.
Click Check my progress to verify the objective.
Task 3. Launch a Dataflow pipeline to write data from Pub/Sub into Bigtable
In this task, you open a second SSH terminal on training_vm and run commands to launch a Dataflow job to write streaming data from Pub/Sub into Bigtable.
Open a second SSH terminal
- In the current terminal window, click Terminal settings (), and then click New connection.
A second terminal window will open. This new terminal session will not have the required environment variables. In the next step, you set these variables on the new terminal session.
- To set the environment variables in the new terminal, run the following command:
This script sets the $DEVSHELL_PROJECT_ID
and $BUCKET
environment variables in the new terminal window.
Launch a Dataflow Pipeline
- To navigate to the code directory in the new terminal, run the following command:
- To review the script using nano, run the following command:
Do not modify the code.
This script takes three required arguments to run a Dataflow job:
- Project ID
- Cloud Storage bucket name
- Java classname
- optional fourth argument for options
In the next steps, you use the --bigtable
option to direct the Dataflow pipeline to write data into Bigtable.
-
To exit nano, press CTRL+X.
-
To launch the Dataflow pipeline to read from Pub/Sub and write into Bigtable, run the following command:
When the pipeline has been launched successfully, you will see a message similar to the following:
Explore the Dataflow pipeline
-
In the Google Cloud console, on the Navigation menu, under Analytics, click Dataflow > Jobs.
-
Click on the new pipeline job name.
-
Locate the write:cbt step in the pipeline graph, and to see the details of the writer, click on the down arrow next to write:cbt.
-
Click on the provided writer, and review the details provided within Step info.
Click Check my progress to verify the objective.
Task 4. Verify streaming data loaded into Bigtable
In a previous task, you already configured the .cbtrc
configuration file in Cloud Shell. You can now run a simple cbt
CLI command to query the first five records of the table.
- To see the first five rows of data and their values in the lane column family, run the following command:
The output is structured as follows:
The output values will resemble the following:
Task 5. Stop streaming jobs and delete Bigtable data
In this final task, you stop the streaming data job and delete the Bigtable instance and table using commands.
Stop simulated streaming data
- In the first SSH terminal with the streaming data simulator, to stop the simulation, press CONTROL+C.
Stop the Dataflow job
-
In the Google Cloud console, on the Navigation menu, click Dataflow > Jobs.
-
Click on the pipeline job name.
-
Click Stop.
-
Select Cancel, and then click Stop job.
Delete a Bigtable table and instance
- To delete the Bigtable table, in Cloud Shell, run the following command:
- To delete the Bigtable instance, run the following command:
If prompted to confirm, type Y.
Click Check my progress to verify the objective.
Congratulations!
In this lab, you used commands to create a new Bigtable instance and table, streamed data into the table using Dataflow, and confirmed that the data was successfully streaming into Bigtable by running simple cbt
CLI commands. You completed the lab by using commands to stop the job and delete the Bigtable table and instance.
Next steps / Learn more
- Check out the lab titled Monitoring and Managing Bigtable Health and Performance.
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated May 30, 2024
Lab Last Tested August 3, 2023
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.