删除实例

根据实例 ID 从当前项目中删除实例。

代码示例

C#

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

// Deletes an instance from the project.
// Initialize request argument(s).
DeleteInstanceRequest request = new DeleteInstanceRequest
{
    InstanceName = new InstanceName(projectId, instanceId)
};
try
{
    // Make request.
    Console.WriteLine("Waiting for operation to complete...");
    bigtableInstanceAdminClient.DeleteInstance(request);
}
catch (Exception ex)
{
    Console.WriteLine($"Exception while deleting {instanceId} instance");
    Console.WriteLine(ex.Message);
}

C++

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

namespace cbt = ::google::cloud::bigtable;
[](cbt::InstanceAdmin instance_admin, std::string const& instance_id) {
  google::cloud::Status status = instance_admin.DeleteInstance(instance_id);
  if (!status.ok()) throw std::runtime_error(status.message());
  std::cout << "Successfully deleted the instance " << instance_id << "\n";
}

Java

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

try {
  adminClient.deleteInstance(instanceId);
  System.out.println("Instance deleted: " + instanceId);
} catch (NotFoundException e) {
  System.err.println("Failed to delete non-existent instance: " + e.getMessage());
}

Node.js

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

console.log('Deleting Instance');
await instance.delete();
console.log(`Instance deleted: ${instance.id}`);

PHP

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

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

/**
 * Delete a bigtable instance
 *
 * @param string $projectId The Google Cloud project ID
 * @param string $instanceId The ID of the Bigtable instance to be deleted
 */
function delete_instance(
    string $projectId,
    string $instanceId
): void {
    $instanceAdminClient = new BigtableInstanceAdminClient();
    $instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);

    printf('Deleting Instance' . PHP_EOL);
    try {
        $instanceAdminClient->deleteInstance($instanceName);
        printf('Deleted Instance: %s.' . PHP_EOL, $instanceId);
    } catch (ApiException $e) {
        if ($e->getStatus() === 'NOT_FOUND') {
            printf('Instance %s does not exists.' . PHP_EOL, $instanceId);
        } else {
            throw $e;
        }
    }
}

Python

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

print("\nDeleting instance")
if not instance.exists():
    print("Instance {} does not exist.".format(instance_id))
else:
    instance.delete()
    print("Deleted instance: {}".format(instance_id))

Ruby

如需了解如何安装和使用 Bigtable 的客户端库,请参阅 Bigtable 客户端库

instance.delete

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器