Delete an instance asynchronously

Delete an instance asynchronously.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Java

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

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import com.google.api.core.ApiFuture;
import com.google.bigtable.admin.v2.DeleteInstanceRequest;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClientV2;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class DeleteInstanceAsync {

  /** Asynchronously deletes the specified Cloud Bigtable instance. */
  public static void deleteInstanceAsync(String projectId, String instanceId)
      throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    // String projectId = "my-project-id";
    // String instanceId = "my-instance-id";

    try (BigtableInstanceAdminClientV2 adminClient = BigtableInstanceAdminClientV2.create()) {
      String name = "projects/" + projectId + "/instances/" + instanceId;
      DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name).build();
      ApiFuture<Empty> future = adminClient.deleteInstanceCallable().futureCall(request);
      future.get();
      System.out.println("Instance deleted: " + instanceId);
    }
  }
}

Python

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

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

from google.api_core.exceptions import NotFound

from google.cloud import bigtable_admin_v2

async with bigtable_admin_v2.BigtableInstanceAdminAsyncClient() as client:
    instance_path = client.instance_path(project_id, instance_id)

    print("\nDeleting instance")
    try:
        await client.delete_instance(name=instance_path)
        print(f"Deleted instance: {instance_id}")
    except NotFound:
        print(f"Instance {instance_id} does not exist.")

What's next

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