インスタンスの削除

インスタンス ID を指定して、現在のプロジェクトからインスタンスを削除します。

さらに詳しい情報

このコードサンプルを含む詳細なドキュメントについては、以下をご覧ください。

コードサンプル

C++

Bigtable 用のクライアント ライブラリをインストールして使用する方法については、Bigtable クライアント ライブラリをご覧ください。

Bigtable で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

C#

Bigtable 用のクライアント ライブラリをインストールして使用する方法については、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);
}

Java

Bigtable 用のクライアント ライブラリをインストールして使用する方法については、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 クライアント ライブラリをご覧ください。

Bigtable で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

PHP

Bigtable 用のクライアント ライブラリをインストールして使用する方法については、Bigtable クライアント ライブラリをご覧ください。

Bigtable で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

/**
 * 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 {
        $deleteInstanceRequest = (new DeleteInstanceRequest())
            ->setName($instanceName);
        $instanceAdminClient->deleteInstance($deleteInstanceRequest);
        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 クライアント ライブラリをご覧ください。

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 クライアント ライブラリをご覧ください。

Bigtable で認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

instance.delete

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。