Create an AppProfile

Stay organized with collections Save and categorize content based on your preferences.

Create an AppProfile.

Code sample


To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

namespace cbt = ::google::cloud::bigtable;
namespace cbta = ::google::cloud::bigtable_admin;
using ::google::cloud::StatusOr;
[](cbta::BigtableInstanceAdminClient instance_admin,
   std::string const& project_id, std::string const& instance_id,
   std::string const& profile_id) {
  std::string instance_name = cbt::InstanceName(project_id, instance_id);

  google::bigtable::admin::v2::AppProfile ap;

  StatusOr<google::bigtable::admin::v2::AppProfile> profile =
      instance_admin.CreateAppProfile(instance_name, profile_id,
  if (!profile) throw std::move(profile).status();
  std::cout << "New profile created with name=" << profile->name() << "\n";


To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
use Google\Cloud\Bigtable\Admin\V2\AppProfile;
use Google\Cloud\Bigtable\Admin\V2\AppProfile\SingleClusterRouting;
use Google\ApiCore\ApiException;

 * Create an App Profile
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance
 * @param string $clusterId The ID of the cluster where the new App Profile will route it's requests(in case of single cluster routing)
 * @param string $appProfileId The ID of the App Profile to create
function create_app_profile(
    string $projectId,
    string $instanceId,
    string $clusterId,
    string $appProfileId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);

    $appProfile = new AppProfile([
        'name' => $appProfileId,
        'description' => 'Description for this newly created AppProfile'

    // create a new routing policy
    // allow_transactional_writes refers to Single-Row-Transactions(
    $routingPolicy = new SingleClusterRouting([
        'cluster_id' => $clusterId,
        'allow_transactional_writes' => false

    // set the newly created routing policy to our app profile

    // we could also create a multi cluster routing policy like so:
    // $routingPolicy = new \Google\Cloud\Bigtable\Admin\V2\AppProfile\MultiClusterRoutingUseAny();
    // $appProfile->setMultiClusterRoutingUseAny($routingPolicy);

    printf('Creating a new AppProfile %s' . PHP_EOL, $appProfileId);

    try {
        $newAppProfile = $instanceAdminClient->createAppProfile($instanceName, $appProfileId, $appProfile);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'ALREADY_EXISTS') {
            printf('AppProfile %s already exists.', $appProfileId);
        throw $e;

    printf('AppProfile created: %s', $newAppProfile->getName());

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.