Testing Access to Google Bigtable

This is a minimal PHP script that’s useful for verifying connectivity and permissions to read data from a Google Bigtable instance. Unlike some of the sparse examples in Google’s PHP SDK, this script will work for any table, and you don’t need to know anything about the structure of the table. This script tests the critical elements that need to work together to enable Bigtable access:

  • Credential file
  • GRPC extension for PHP
  • Protobuf extension for PHP
  • Scopes enabled on Compute Engine instances
  • IAM roles assigned to service account used in Kubernetes when Workload Identity is enabled
<?php

require 'vendor/autoload.php';
use Google\Cloud\Bigtable\BigtableClient;

$project_id = 'my-project-id';
$instance_id = 'my-instance-id';
$table_id = 'my-table-id';
$credential_file_path = './credential.json';
$transport = 'grpc';

// Connect to an existing table with an existing instance.
$dataClient = new BigtableClient([
    'projectId' => $project_id,
    'credentials' => $credential_file_path,
    'transport' => $transport,
]);
$table = $dataClient->table($instance_id, $table_id);

// Read multiple rows
$rows = $table->readRows(['rowsLimit' => 2]);
foreach ($rows as $row) {
  print_r($row) . PHP_EOL;
}

The latest version can always be found as a Gist on GitHub. Here’s the current composer.json that I’m using:

{
    "require": {
        "google/cloud-bigtable": "^1.3",
        "grpc/grpc": "^v1.27.0"
    }
}

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.