If you're learning about Cloud Bigtable, you can work through a quickstart to get a taste of the fundamentals that you would use at scale in a production environment.
This quickstart uses the cbt
command-line tool. If you prefer to use the
HBase shell, follow the quickstart using the HBase shell
instead.
In this quickstart, you perform the following actions:
- Connect to a Cloud Bigtable instance.
- Perform basic administrative tasks.
- Write data to a table.
- Read data from a table.
You can do this quickstart using the Cloud Shell or in your local terminal window.
Select or create a GCP project. If you don't plan to keep the resources you create in this quickstart, create a new project. After you've completed the quickstart, delete the project.
Make sure billing is enabled for your Google Cloud project. Learn how to confirm that billing is enabled for your project.
Enable the Cloud Bigtable and Cloud Bigtable Admin APIs.
After you enable the APIs, click Go to credentials.
On the Credentials page, answer the required questions:
- In response to "Which API are you using?", choose Cloud Bigtable API.
- Answer the question about App Engine or Compute Engine. For this quickstart, you are not using them.
- Click What credentials do I need?
- If you are prompted to create a service account, provide the following
information:
- Choose a name for your service account.
- For Role, choose Cloud Bigtable > Bigtable Administrator.
- For Key type, select JSON.
- Click Continue.
- Save the newly created service account key JSON file to your local
HOME
directory or your preferred location. You can skip this step if you plan to complete the quickstart in the Cloud Shell.
- If you are not prompted to create a new service account, click Done.
Open a terminal window, either locally or with Cloud Shell:
If you are using your local terminal window, set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
. Replace [PATH] with the file path of the JSON file that contains your service account key.export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"
For example:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"
If you are using your local terminal window and you have not previously installed the Cloud SDK and the
cbt
tool, do so now. If you are using the Cloud Shell, these tools are preinstalled and you can skip these steps.Install the
cbt
command-line tool:gcloud components update
gcloud components install cbt
Create a Cloud Bigtable instance
Open the Create instance page in the Google Cloud Console.
For Instance name, enter
Quickstart instance
.For Instance ID, enter
quickstart-instance
.For Storage type, select SSD.
For Cluster ID, enter
quickstart-instance-c1
.For Region, select a region near you.
For Zone, select a zone in the region you selected.
Click Create to create the instance.
Connect to your instance
Configure
cbt
to use your project and instance by creating a.cbtrc
file, replacing project-id with the ID for the project where you created your Cloud Bigtable instance:echo project = project-id > ~/.cbtrc
echo instance = quickstart-instance >> ~/.cbtrc
Verify that you set up the
.cbtrc
file correctly:cat ~/.cbtrc
The terminal displays the contents of the
.cbtrc
file, which looks similar to the following:project = project-id instance = quickstart-instance
Now you can use the
cbt
tool with your instance.
Read and write data
Cloud Bigtable stores data in tables, which contain rows. Each row is identified by a row key.
Data in a row is organized into column families, which are groups of columns. A column qualifier identifies a single column within a column family.
There can be multiple time-stamped versions of the value at the intersection of a row and column. Each version is referred to as a cell.
Create a table named
my-table
.cbt createtable my-table
List your tables:
cbt ls
The command displays output similar to the following:
my-table
Add one column family named
cf1
:cbt createfamily my-table cf1
List your column families:
cbt ls my-table
The command displays output similar to the following:
Family Name GC Policy ----------- --------- cf1 <never>
Put the value
test-value
in the rowr1
, using the column familycf1
and the column qualifierc1
:cbt set my-table r1 cf1:c1=test-value
Use the
cbt read
command to read the data you added to the table:cbt read my-table
The shell displays output similar to the following:
---------------------------------------- r1 cf1:c1 @ 2019/11/26-15:05:38.840000 "test-value"
A timestamp is added automatically because you did not specify one.
Clean up
To avoid incurring charges to your Google Cloud account for the resources
used in this quickstart, delete the instance. Deleting the .cbtrc
file leaves
you ready to work on a different project.
Delete the table
my-table
:cbt deletetable my-table
Delete the instance:
cbt deleteinstance quickstart-instance
Delete the
.cbtrc
file:rm ~/.cbtrc