Checkpoint
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.
What you need
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab.
Log in to Google Cloud Console
- Using the browser tab or window you are using for this lab session, copy the Username from the Connection Details panel and click the Open Google Console button.
- Paste in the Username, and then the Password as prompted.
- Click Next.
- Accept the terms and conditions.
Since this is a temporary account, which will last only as long as this lab:
- Do not add recovery options
- Do not sign up for free trials
- Once the console opens, view the list of services by clicking the Navigation menu (
) at the top-left.
Activate Cloud Shell
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.
Sample commands
- List the active account name:
(Output)
(Example output)
- List the project ID:
(Output)
(Example output)
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.
Manual Last Updated April 25, 2024
Lab Last Tested August 3, 2023
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.