버킷 삭제
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Cloud Storage 버킷 삭제를 보여줍니다.
더 살펴보기
이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.
코드 샘플
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],[],[],[],null,["Demonstrates deleting a Cloud Storage bucket.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Delete buckets](/storage/docs/deleting-buckets)\n\nCode sample \n\nC++\n\n\nFor more information, see the\n[Cloud Storage C++ API\nreference documentation](/cpp/docs/reference/storage/latest).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n namespace gcs = ::google::cloud::storage;\n [](gcs::Client client, std::string const& bucket_name) {\n google::cloud::Status status = client.DeleteBucket(bucket_name);\n if (!status.ok()) throw std::runtime_error(status.message());\n\n std::cout \u003c\u003c \"The bucket \" \u003c\u003c bucket_name \u003c\u003c \" was deleted successfully.\\n\";\n }\n\nC#\n\n\nFor more information, see the\n[Cloud Storage C# API\nreference documentation](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n\n using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest/Google.Cloud.Storage.V1.html;\n using System;\n\n public class DeleteBucketSample\n {\n public void DeleteBucket(string bucketName = \"your-unique-bucket-name\")\n {\n var storage = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest/Google.Cloud.Storage.V1.StorageClient.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Storage.V1/latest/Google.Cloud.Storage.V1.StorageClient.html#Google_Cloud_Storage_V1_StorageClient_Create();\n storage.DeleteBucket(bucketName);\n Console.WriteLine($\"The bucket {bucketName} was deleted.\");\n }\n }\n\nGo\n\n\nFor more information, see the\n[Cloud Storage Go API\nreference documentation](https://pkg.go.dev/cloud.google.com/go/storage).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n \t\"time\"\n\n \t\"cloud.google.com/go/storage\"\n )\n\n // deleteBucket deletes the bucket.\n func deleteBucket(w io.https://cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest/index.html#cloud_google_com_go_storage_Writer, bucketName string) error {\n \t// bucketName := \"bucket-name\"\n \tctx := context.Background()\n \tclient, err := storage.NewClient(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"storage.NewClient: %w\", err)\n \t}\n \tdefer client.Close()\n\n \tctx, cancel := context.WithTimeout(ctx, time.Second*30)\n \tdefer cancel()\n\n \tbucket := client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest/index.html#cloud_google_com_go_storage_Client_Bucket(bucketName)\n \tif err := bucket.Delete(ctx); err != nil {\n \t\treturn fmt.Errorf(\"Bucket(%q).Delete: %w\", bucketName, err)\n \t}\n \tfmt.Fprintf(w, \"Bucket %v deleted\\n\", bucketName)\n \treturn nil\n }\n\nJava\n\n\nFor more information, see the\n[Cloud Storage Java API\nreference documentation](https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/overview).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n import com.google.cloud.storage.https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket.html;\n import com.google.cloud.storage.https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Storage.html;\n import com.google.cloud.storage.https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.StorageOptions.html;\n\n public class DeleteBucket {\n public static void deleteBucket(String projectId, String bucketName) {\n // The ID of your GCP project\n // String projectId = \"your-project-id\";\n\n // The ID of the bucket to delete\n // String bucketName = \"your-unique-bucket-name\";\n\n https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Storage.html storage = https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.StorageOptions.html.newBuilder().setProjectId(projectId).build().https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.transfermanager.TransferManagerConfig.html#com_google_cloud_storage_transfermanager_TransferManagerConfig_getService__();\n https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket.html bucket = storage.https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Storage.html#com_google_cloud_storage_Storage_get_com_google_cloud_storage_BlobId_(bucketName);\n bucket.https://cloud.google.com/java/docs/reference/google-cloud-storage/latest/com.google.cloud.storage.Bucket.html#com_google_cloud_storage_Bucket_delete_com_google_cloud_storage_Bucket_BucketSourceOption____();\n\n System.out.println(\"Bucket \" + bucket.getName() + \" was deleted\");\n }\n }\n\nNode.js\n\n\nFor more information, see the\n[Cloud Storage Node.js API\nreference documentation](https://cloud.google.com/nodejs/docs/reference/storage/latest).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n /**\n * TODO(developer): Uncomment the following lines before running the sample.\n */\n // The ID of your GCS bucket\n // const bucketName = 'your-unique-bucket-name';\n\n // Imports the Google Cloud client library\n const {Storage} = require('https://cloud.google.com/nodejs/docs/reference/storage/latest/overview.html');\n\n // Creates a client\n const storage = new Storage();\n\n async function deleteBucket() {\n await storage.bucket(bucketName).delete();\n console.log(`Bucket ${bucketName} deleted`);\n }\n\n deleteBucket().catch(console.error);\n\nPHP\n\n\nFor more information, see the\n[Cloud Storage PHP API\nreference documentation](https://googleapis.github.io/google-cloud-php/#/docs/google-cloud/latest/storage/storageclient).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n use Google\\Cloud\\Storage\\StorageClient;\n\n /**\n * Delete a Cloud Storage Bucket.\n *\n * @param string $bucketName The name of your Cloud Storage bucket.\n * (e.g. 'my-bucket')\n */\n function delete_bucket(string $bucketName): void\n {\n $storage = new StorageClient();\n $bucket = $storage-\u003ebucket($bucketName);\n $bucket-\u003edelete();\n printf('Bucket deleted: %s' . PHP_EOL, $bucket-\u003ename());\n }\n\nPython\n\n\nFor more information, see the\n[Cloud Storage Python API\nreference documentation](https://cloud.google.com/python/docs/reference/storage/latest).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n from google.cloud import https://cloud.google.com/python/docs/reference/storage/latest/\n\n\n def delete_bucket(bucket_name):\n \"\"\"Deletes a bucket. The bucket must be empty.\"\"\"\n # bucket_name = \"your-bucket-name\"\n\n storage_client = https://cloud.google.com/python/docs/reference/storage/latest/.https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.client.Client.html()\n\n bucket = storage_client.https://cloud.google.com/python/docs/reference/storage/latest/google.cloud.storage.client.Client.html#google_cloud_storage_client_Client_get_bucket(bucket_name)\n bucket.delete()\n\n print(f\"Bucket {bucket.name} deleted\")\n\nRuby\n\n\nFor more information, see the\n[Cloud Storage Ruby API\nreference documentation](https://googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage.html).\n\n\nTo authenticate to Cloud Storage, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for client libraries](/storage/docs/authentication#client-libs).\n\n def delete_bucket bucket_name:\n # The ID of your GCS bucket\n # bucket_name = \"your-unique-bucket-name\"\n\n require \"google/cloud/storage\"\n\n storage = Google::Cloud::https://cloud.google.com/ruby/docs/reference/google-cloud-storage-control-v2/latest/Google-Cloud-Storage.html.https://cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage.html\n bucket = storage.bucket bucket_name, skip_lookup: true\n\n bucket.delete\n\n puts \"Deleted bucket: #{bucket.name}\"\n end\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=storage)."]]