Quickstart using the cbt tool

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.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  4. Enable the Cloud Bigtable, Cloud Bigtable Admin APIs.

    Enable the APIs

  5. Create a service account:

    1. In the Cloud Console, go to the Create service account page.

      Go to Create service account
    2. Select a project.
    3. In the Service account name field, enter a name. The Cloud Console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    4. Click Create and continue.
    5. Click the Select a role field, then click Bigtable Administrator.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  6. Create a service account key:

    1. In the Cloud Console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  7. Install and initialize the Cloud SDK.
  8. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  9. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

  10. Enable the Cloud Bigtable, Cloud Bigtable Admin APIs.

    Enable the APIs

  11. Create a service account:

    1. In the Cloud Console, go to the Create service account page.

      Go to Create service account
    2. Select a project.
    3. In the Service account name field, enter a name. The Cloud Console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    4. Click Create and continue.
    5. Click the Select a role field, then click Bigtable Administrator.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  12. Create a service account key:

    1. In the Cloud Console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  13. Install and initialize the Cloud SDK.

Create a Bigtable instance

  1. Open the Create instance page in the Google Cloud Console.

    Create an instance

  2. For Instance name, enter Quickstart instance.

  3. For Instance ID, enter quickstart-instance.

  4. For Storage type, select SSD.

  5. For Cluster ID, enter quickstart-instance-c1.

  6. For Region, select a region near you.

  7. For Zone, select a zone in the region you selected.

  8. Click Create to create the instance.

Connect to your instance

  1. 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 Bigtable instance:

       echo project = project-id > ~/.cbtrc
       echo instance = quickstart-instance >> ~/.cbtrc

  2. 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

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.

  1. Create a table named my-table.

       cbt createtable my-table

  2. List your tables:

       cbt ls

    The command displays output similar to the following:

        my-table

  3. Add one column family named cf1:

       cbt createfamily my-table cf1

  4. List your column families:

       cbt ls my-table

    The command displays output similar to the following:

        Family Name     GC Policy
        -----------     ---------
        cf1             <never>

  5. Put the value test-value in the row r1, using the column family cf1 and the column qualifier c1:

       cbt set my-table r1 cf1:c1=test-value

  6. 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.

  1. Delete the table my-table:

       cbt deletetable my-table

  2. Delete the instance:

       cbt deleteinstance quickstart-instance
  3. Delete the .cbtrc file:

       rm ~/.cbtrc