ご利用のバケットが不要になった場合は、課金をすべて停止するために削除できます。Object Storage Service (OSS) の料金はバケット内のリソースに対して課金されるため、バケットを削除する前にすべてのリソースをクリアする必要があります。バケットを削除することが、見落とされた課金対象リソースによる予期せぬ料金発生を防ぐ最も確実な方法です。バケットを削除するとデータは復元できなくなり、リリース後は他のユーザーがその名前を取得できる点にご注意ください。OSS の利用を完全に停止するには、ご利用のアカウント内のすべてのバケットを削除する必要があります。
削除前のリスク評価
取り返しのつかないデータ損失のリスク
この操作は取り消すことができず、すべてのオブジェクト、その以前のバージョン、およびフラグメントを恒久的に削除します。事前にデータをバックアップしてください。
サービス中断のリスク
バケットを削除すると、それに依存するウェブサイト、アプリケーション、CDN サービスが即座に中断されます。バケットにアクティブにアクセスしているサービスがないことを確認してください。
バケット名の横取りリスク
バケットを削除すると、その名前はリリースされるまで 4~8 時間の解約待機期間に入ります。名前を確保する必要がある場合は、バケットを削除せずに空にする方法を推奨します。
同期削除のリスク
クロスリージョンレプリケーションまたは同一リージョンレプリケーションを有効にしている場合、削除操作によって送信先バケットのデータもクリアされる可能性があります。構成を確認してください。
コストと所要時間の見積もり
多数のオブジェクトをクリーンアップすると API リクエスト料金が発生し、データ量によっては数時間以上かかる場合があります。
削除が必要なリソースの確認
オブジェクト、フラグメント、アクセスポイント、アクセラレータ、または RTMP アップストリーミング URL などのリソースを含むバケットを削除しようとすると、「The bucket is not empty」(バケットが空ではありません)というエラーが表示されます。OSS コンソールの削除ウィザードを使用することを推奨します。このウィザードでは、クリーンアップが必要なすべての項目を自動的にスキャンして一覧表示します。
-
OSS コンソールにログインします。
-
左側のナビゲーションウィンドウで、バケット をクリックします。表示されたページで、対象バケットの名前をクリックします。
左側のナビゲーションウィンドウで下にスクロールし、バケットの削除 をクリックします。
バケットの削除 ページで、バケットを削除する をクリックします。その後、クリーンアップが必要な項目を確認できます。

必要なリソースのクリーンアップ
バケットを削除するには、まずすべてのリソースをクリアする必要があります。システムが特定したリソースをクリーンアップしてください。バケットに多数のオブジェクトが含まれる場合は、ライフサイクルルールを使用してクリーンアップを自動化することを推奨します。
オブジェクト
objects リソースのステータス列に HDFS 機能が有効であることが示されている場合は、まず HDFS オブジェクトをクリーンアップする必要があります。バージョン管理が有効になっている場合、Objects ページには現在のバージョンとすべての以前のバージョンが表示されます。そのため、すべてのオブジェクトを選択して削除すると、すべてのバージョンが削除されます。
OSS オブジェクト
OSS コンソール
バケットの削除 ページで、バケットを削除する をクリックし、objects リソースを見つけ、削除 をクリックします。
すべてのオブジェクトを選択し、ページ下部の 完全に削除 をクリックします。
表示されたダイアログボックスで、OK をクリックします。
ossutil
現在および以前のバージョンを含む、バケット内のすべてのオブジェクトを削除します。
ossutil rm oss://examplebucket/ -r詳細な例については、「rm (delete)」をご参照ください。
HDFS オブジェクト
OSS コンソール
object リソースの Status 列で、Pause Now をクリックして HDFS バックグラウンドタスクを停止します。
削除 をクリックして HDFS タブに移動します。
すべての HDFS ファイルが削除されるまで、完全に削除 を順次クリックします。
HDFS シェルコマンド
hdfs dfs -rm -r -skipTrash oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/*詳細については、「HDFS シェルコマンドを使用した OSS-HDFS サービスの一般的な操作」をご参照ください。
パート
フラグメントは、未完了のマルチパートアップロードによって生成されたオブジェクトの断片です。
OSS コンソール
バケットの削除 ページで、バケットを削除する をクリックし、フラグメント リソース項目を見つけ、削除 をクリックします。
オブジェクト ページで、Part Management をクリックします。
フラグメント(Multipart) パネルで、すべて削除 をクリックします。
ダイアログボックスで、OK をクリックします。
ossutil
未完了またはキャンセルされたマルチパートアップロードのすべてのフラグメントを削除します。
ossutil rm oss://examplebucket -m -r -f詳細については、「rm (delete)」をご参照ください。
アクセスポイント
左側のナビゲーションバーで、エンドポイント をクリックします。
各アクセスポイントについて、Delete Access Point をクリックします。
画面の指示に従って、対応するアクセスポリシーを削除します。
アクセスポリシーを削除したら、アクセスポイントの一覧に戻ります。指示に従ってアクセスポイント名を入力し、OK をクリックして削除を完了します。
アクセラレータ
アクセラレータを削除しても、キャッシュデータのみがクリアされ、OSS バケットに保存されているデータには影響しません。
左側のナビゲーションバーで、バケットの設定 > アクセラレータ をクリックします。
OSS アクセラレータの一覧で、操作 列の 削除 をクリックします。
ページの指示に従ってアクセラレータ名を入力し、OK をクリックして削除を完了します。

RTMP アップストリーミング URL
OSS コンソールやツールを使用して、バケットの LiveChannel を表示または削除することはできません。代わりに、SDK を使用するか API を呼び出してください。詳細については、「DeleteLiveChannel」API ドキュメントをご参照ください。以下のサンプルコードは、指定された LiveChannel を削除する方法を示しています。
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.LiveChannelGenericRequest;
/**
* This code provides an example of how to delete a specified LiveChannel.
* This program demonstrates how to delete a LiveChannel in Alibaba Cloud OSS.
*/
public class Demo {
public static void main(String[] args) throws Exception {
// The OSS endpoint. Select an endpoint based on your region. This example uses the endpoint for the China (Hangzhou) region.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Obtain access credentials from environment variables. Before you run this code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name. For example, examplebucket.
String bucketName = "examplebucket";
// Specify the LiveChannel name.
String liveChannelName = "yourLiveChannelName";
// Specify the region where the bucket is located. For example, set Region to cn-hangzhou for China (Hangzhou).
String region = "cn-hangzhou";
// Create an OSSClient instance.
// When the OSSClient instance is no longer needed, call the shutdown method to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Create a request to delete the LiveChannel.
LiveChannelGenericRequest request = new LiveChannelGenericRequest(bucketName, liveChannelName);
// Execute the delete operation.
ossClient.deleteLiveChannel(request);
} catch (OSSException oe) {
// Handle exceptions returned by the OSS server.
oe.printStackTrace();
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (Exception e) {
System.out.println("Caught an unexpected exception:");
e.printStackTrace();
} finally {
if (ossClient != null) {
// Release OSSClient resources.
ossClient.shutdown();
}
}
}
}バケットの削除
バケット内のすべてのリソースがクリアされたことを確認したら、バケットを削除できます。
OSS コンソール
対象バケットの バケットの削除 ページに戻ります。
バケットを削除する をクリックし、指示に従ってバケット名を入力してから、OK をクリックして削除を完了します。
ossutil
以下のコマンドは、examplebucket という名前のバケットを削除します。
ossutil api delete-bucket --bucket examplebucket詳細については、「delete-bucket」をご参照ください。
OSS SDK
以下のセクションでは、一般的な SDK を使用してバケットを削除するコード例を示します。その他の SDK については、「SDK 概要」をご参照ください。
Java
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
public class Demo {
public static void main(String[] args) throws Exception {
// In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the name of the bucket. Example: examplebucket.
String bucketName = "examplebucket";
// Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to cn-hangzhou.
String region = "cn-hangzhou";
// Create an OSSClient instance.
// Call the shutdown method to release associated resources when the OSSClient is no longer in use.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Delete the bucket.
ossClient.deleteBucket(bucketName);
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
} Python
import argparse
import alibabacloud_oss_v2 as oss
# Create a command-line argument parser and describe that this script is used to delete a specified OSS bucket.
parser = argparse.ArgumentParser(description="Delete a specified OSS bucket.")
# Add the --region command-line argument, which specifies the region where the bucket is located. This argument is required.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
# Add the --bucket command-line argument, which specifies the name of the bucket. This argument is required.
parser.add_argument('--bucket', help='The name of the bucket to delete.', required=True)
# Add the --endpoint command-line argument, which specifies the domain name that other services can use to access OSS. This argument is not required.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS.')
def main():
"""
The main function, which is used to parse command-line arguments and delete the specified bucket.
"""
args = parser.parse_args() # Parse command-line arguments.
# Load credentials from environment variables for identity verification.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
# Use the default configurations of the SDK and set the credential provider and region.
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
# If the endpoint parameter is provided, set the endpoint in the configuration.
if args.endpoint is not None:
cfg.endpoint = args.endpoint
# Create an OSS client based on the configurations.
client = oss.Client(cfg)
# Construct a request to delete the specified bucket.
request = oss.DeleteBucketRequest(bucket=args.bucket)
try:
# Send the request and obtain the response.
result = client.delete_bucket(request)
# Print the status code and request ID of the response.
print(f'status code: {result.status_code},'
f' request id: {result.request_id}')
except oss.exceptions.OssError as e:
# Catch and print possible exceptions.
print(f"Failed to delete bucket: {e}")
if __name__ == "__main__":
main() # The script entry point. The main function is called when the file is run.
Go
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)
var (
region string
bucketName string
)
func init() {
// Define command line parameters to specify the region and name of the bucket.
flag.StringVar(®ion, "region", "", "The region in which the bucket is located.")
flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.")
}
func main() {
// Parse command line parameters.
flag.Parse()
// Check whether the name of the bucket is specified.
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required")
}
// Check whether the region is specified.
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
// Load the default configurations and specify the credential provider and region.
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
// Create an OSS client.
client := oss.NewClient(cfg)
// Create a request object for deletion.
request := &oss.DeleteBucketRequest{
Bucket: oss.Ptr(bucketName),
}
// Call the DeleteBucket method.
result, err := client.DeleteBucket(context.TODO(), request)
if err != nil {
log.Fatalf("failed to delete bucket %v", err)
}
// Display the result.
log.Printf("delete bucket result:%#v\n", result)
}
PHP
<?php
require_once __DIR__ . '/../vendor/autoload.php'; // Automatically load objects and dependency libraries.
use AlibabaCloud\Oss\V2 as Oss;
// Specify command line parameters.
$optsdesc = [
"region" => ['help' => The region in which the bucket is located.', 'required' => True], // (Required) Specify the region in which the bucket is located. Example: oss-cn-hangzhou.
"endpoint" => ['help' => The domain names that other services can use to access OSS.', 'required' => False], // (Optional) Specify the endpoint that can be used by other services to access OSS.
"bucket" => ['help' => The name of the bucket, 'required' => True], // (Required) Specify the name of the bucket.
];
$longopts = \array_map(function ($key) {
return "$key:"; // Add a colon (:) to the end of each parameter to indicate that a value is required.
}, array_keys($optsdesc));
// Parse the command line parameters.
$options = getopt("", $longopts);
// Check whether the required parameters are configured.
foreach ($optsdesc as $key => $value) {
if ($value['required'] === True && empty($options[$key])) {
$help = $value['help'];
echo "Error: the following arguments are required: --$key, $help"; // Specifies that the required parameters are not configured.
exit(1);
}
}
// Obtain the values of the command line parameters.
$region = $options["region"]; // The region in which the bucket is located.
$bucket = $options["bucket"]; // The name of the bucket.
// Use environment variables to load the credential information (AccessKey ID and AccessKey secret).
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();
// Use the default configurations of the SDK.
$cfg=Oss\Config::loadDefault(); // Load the default configurations of the SDK.
$cfg->setCredentialsProvider($credentialsProvider); // Specify the credential provider.
$cfg->setRegion($region); // Specify the region.
if (isset($options["endpoint"])) {
$cfg->setEndpoint($options["endpoint"]); // Specify the endpoint if an endpoint is provided.
}
// Create an OSSClient instance.
$client = new Oss\Client($cfg);
// Create a request to delete the bucket.
$request = new Oss\Models\DeleteBucketRequest($bucket);
// Use the deleteBucket method to delete the bucket.
$result = $client->deleteBucket($request);
// Display the returned result.
printf(
'status code:' . $result-> statusCode. PHP_EOL . // The HTTP response status code.
'request id:' . $result->requestId // The unique identifier of the request.
);
Node.js
const OSS = require('ali-oss');
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
region: 'yourregion',
// Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
authorizationV4: true,
// Set bucket to the name of your bucket.
bucket: 'yourBucketName',
});
async function deleteBucket() {
try {
// Specify the bucket name.
const result = await client.deleteBucket('yourbucketname');
console.log(result);
} catch (err) {
console.log(err);
}
}
deleteBucket();.NET
using System;
using Aliyun.OSS;
using Aliyun.OSS.Common;
namespace Samples
{
public class Program
{
public static void Main(string[] args)
{
// Set endpoint to the Endpoint of the region where your bucket is located. For example, if your bucket is in the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com.
var endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
var accessKeyId = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_ID");
var accessKeySecret = Environment.GetEnvironmentVariable("OSS_ACCESS_KEY_SECRET");
// Set bucketName to the name of your bucket. Example: examplebucket.
var bucketName = "examplebucket314";
// Set region to the ID of the region where your bucket is located. For example, if your bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.
const string region = "cn-hangzhou";
// Create a ClientConfiguration instance and modify the default parameters as needed.
var conf = new ClientConfiguration();
// Set the signature version to V4.
conf.SignatureVersion = SignatureVersion.V4;
// Create an OssClient instance.
var client = new OssClient(endpoint, accessKeyId, accessKeySecret, conf);
client.SetRegion(region);
try
{
client.DeleteBucket(bucketName);
Console.WriteLine("Delete bucket succeeded");
}
catch (Exception ex)
{
Console.WriteLine("Delete bucket failed. {0}", ex.Message);
}
}
}
}Android
DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest("bucketName");
// Asynchronously delete the bucket.
OSSAsyncTask deleteBucketTask = oss.asyncDeleteBucket(deleteBucketRequest, new OSSCompletedCallback<DeleteBucketRequest, DeleteBucketResult>() {
@Override
public void onSuccess(DeleteBucketRequest request, DeleteBucketResult result) {
Log.d("asyncDeleteBucket", "Success!");
}
@Override
public void onFailure(DeleteBucketRequest request, ClientException clientException, ServiceException serviceException) {
// The request failed.
if (clientException != null) {
// Client exceptions, such as network exceptions.
clientException.printStackTrace();
}
if (serviceException != null) {
// Service exceptions.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});iOS
OSSDeleteBucketRequest * delete = [OSSDeleteBucketRequest new];
// Specify the bucket name. For example, examplebucket.
delete.bucketName = @"examplebucket";
OSSTask * deleteTask = [client deleteBucket:delete];
[deleteTask continueWithBlock:^id(OSSTask *task) {
if (!task.error) {
NSLog(@"delete bucket success!");
} else {
NSLog(@"delete bucket failed, error: %@", task.error);
}
return nil;
}];
// Block the current thread until the task is complete.
// [getdeleteTask waitUntilFinished];C++
#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;
int main(void)
{
/*Initialize the OSS account information.*/
/*Set yourEndpoint to the Endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the Endpoint to https://oss-cn-hangzhou.aliyuncs.com.*/
std::string Endpoint = "yourEndpoint";
/*Set yourRegion to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou.*/
std::string Region = "yourRegion";
/*Specify the bucket name, for example, examplebucket.*/
std::string BucketName = "examplebucket";
/*Initialize network resources.*/
InitializeSdk();
ClientConfiguration conf;
conf.signatureVersion = SignatureVersionType::V4;
/*Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.*/
auto credentialsProvider = std::make_shared<EnvironmentVariableCredentialsProvider>();
OssClient client(Endpoint, credentialsProvider, conf);
client.SetRegion(Region);
/*Delete the bucket.*/
DeleteBucketRequest request(BucketName);
auto outcome = client.DeleteBucket(request);
if (outcome.isSuccess()) {
std::cout << "Delete bucket successfully." << std::endl;
} else {
std::cout << "Failed to delete bucket. Error code: " << outcome.error().Code()
<< ", Message: " << outcome.error().Message()
<< ", RequestId: " << outcome.error().RequestId() << std::endl;
}
/*Release network resources.*/
ShutdownSdk();
return 0;
}C
#include "oss_api.h"
#include "aos_http_io.h"
/* Set yourEndpoint to the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. */
const char *endpoint = "yourEndpoint";
/* Set the bucket name. Example: examplebucket. */
const char *bucket_name = "examplebucket";
/* Set yourRegion to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the region to cn-hangzhou. */
const char *region = "yourRegion";
void init_options(oss_request_options_t *options)
{
options->config = oss_config_create(options->pool);
/* Use a char* string to initialize the aos_string_t type. */
aos_str_set(&options->config->endpoint, endpoint);
/* Obtain access credentials from environment variables. Before running this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. */
aos_str_set(&options->config->access_key_id, getenv("OSS_ACCESS_KEY_ID"));
aos_str_set(&options->config->access_key_secret, getenv("OSS_ACCESS_KEY_SECRET"));
// Configure the following two additional parameters.
aos_str_set(&options->config->region, region);
options->config->signature_version = 4;
/* Specify whether to use a CNAME to access OSS. A value of 0 indicates that a CNAME is not used. */
options->config->is_cname = 0;
/* Set network parameters, such as the timeout period. */
options->ctl = aos_http_controller_create(options->pool, 0);
}
int main(int argc, char *argv[])
{
/* Call the aos_http_io_initialize method in main() to initialize global resources, such as network and memory resources. */
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
exit(1);
}
/* A memory pool (pool) for memory management, equivalent to apr_pool_t. Its implementation code is in the APR library. */
aos_pool_t *pool;
/* Create a new memory pool. The second parameter is NULL, which indicates that the pool does not inherit from other memory pools. */
aos_pool_create(&pool, NULL);
/* Create and initialize options. This parameter includes global configuration information, such as the endpoint, access_key_id, access_key_secret, is_cname, and curl. */
oss_request_options_t *oss_client_options;
/* Allocate memory for options in the memory pool. */
oss_client_options = oss_request_options_create(pool);
/* Initialize the client options oss_client_options. */
init_options(oss_client_options);
/* Initialize the parameters. */
aos_string_t bucket;
aos_table_t *resp_headers = NULL;
aos_status_t *resp_status = NULL;
/* Assign the char* data to the aos_string_t bucket. */
aos_str_set(&bucket, bucket_name);
/* Delete the bucket. */
resp_status = oss_delete_bucket (oss_client_options, &bucket, &resp_headers);
if (aos_status_is_ok(resp_status)) {
printf("delete bucket succeeded\n");
} else {
printf("delete bucket failed\n");
}
/* Release the memory pool. This releases the memory allocated for resources during the request. */
aos_pool_destroy(pool);
/* Release the previously allocated global resources. */
aos_http_io_deinitialize();
return 0;
}Ruby
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
# The China (Hangzhou) region is used as an example. Specify the actual Endpoint for your region.
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
# Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
access_key_id: ENV['OSS_ACCESS_KEY_ID'],
access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Specify the bucket name. For example, examplebucket.
client.delete_bucket('examplebucket')大容量データの自動クリーンアップ
バケットに大量のオブジェクト(数百万以上)が含まれる場合は、ライフサイクルルールを構成するのが最も効率的かつ費用対効果の高いクリーンアップ方法です。この方法では、「有効期限切れ後に削除」ルールを設定し、指定された期間後にバケット内のすべてのデータを自動的に削除するようシステムに指示します。ライフサイクルルールに不慣れな場合は、本番環境以外のバケットで事前にテストすることを推奨します。
注:オブジェクトの削除は取り消しできない操作です。慎重に実行してください。
バージョン管理無効
バージョン管理が無効なバケットの場合、すべてのオブジェクトとフラグメント(マルチパートアップロードからの未マージフラグメント)を自動かつ迅速にクリーンアップするためのライフサイクルルールを 1 つだけ構成すれば十分です。
OSS コンソールにログインし、Buckets ページに移動してから、対象バケットの名前をクリックします。
左側のナビゲーションウィンドウで、 を選択し、バケットのバージョン管理が無効であることを確認します。

左側のナビゲーションウィンドウで、データ管理 > Lifecycle を選択します。バケット内のすべてのオブジェクトを最終更新日から 1 日後に自動的に削除し、1 日以上前に作成されたフラグメントを自動的にクリーンアップするライフサイクルルールを構成します。

バージョン管理有効
バージョン管理が有効なバケットには、現在のオブジェクトバージョン、以前のオブジェクトバージョン、フラグメント、および削除マーカーが含まれる場合があります。これらすべての項目を自動かつ迅速にクリーンアップするためのライフサイクルルールを 1 つだけ構成すれば十分です。
OSS コンソールにログインし、Buckets ページに移動してから、対象バケットの名前をクリックします。
左側のナビゲーションバーで、 を選択し、バケットのバージョン管理が有効であることを確認します。

左側のナビゲーションバーで、 を選択し、バケット内のすべての現在および以前のバージョンのオブジェクトを最終更新日から 1 日後に自動的に削除し、1 日以上前に作成されたフラグメントを自動的にクリーンアップするライフサイクルルールを構成します。このルールにより、削除マーカーもクリーンアップされます。

よくある質問
「Bucket not empty」エラー
このエラーは、バケット内にまだリソースが残っていることを示しています。必要なリソースのクリーンアップで説明されているように、OSS コンソールを使用して残りのリソースを特定・クリーンアップすることを推奨します。その後、再度バケットの削除を試みてください。
同じ名前のバケットを再作成する場合
バケットを削除すると、その名前は 4~8 時間の解約待機期間に入ります。この期間中は、どのユーザーもその名前で新しいバケットを作成できません。すぐにバケットが必要な場合は、新しい名前を使用してください。
解約待機期間が終了すると、その名前はすべてのユーザーが利用可能になります。すぐにバケットを再作成しない場合、他のユーザーがあなたより先にその名前を取得する可能性があります。
複数のバケットを一括削除する場合
一括削除は高リスク操作であり、恒久的なデータ損失を引き起こす可能性があります。実行する前に、削除対象のバケット一覧を慎重に確認し、必要なデータがすべてバックアップされていることを確認してください。
OSS コンソールは一括削除をサポートしていません。ただし、ossutil を使用してこの操作を実行するスクリプトを作成できます。
コアロジックは次のとおりです。
リストの準備:削除するすべてのバケット名を正確に記載したテキストファイルまたはリストを作成します。
ループ処理:スクリプトでこのリストを繰り返し処理し、各バケット名に対して以下の 2 つの重要なステップを実行します。
バケットの空にする:現在のバケットに対して、ossutil コマンドを呼び出して空にします。
空のバケットを削除する:前のステップが成功したことを確認した後、ossutil コマンドを呼び出してバケットを削除します。
「Insufficient permissions」エラー
バケットを削除する前に、バケット内のすべてのリソースをクリアする必要があります。このプロセスには、一覧表示および削除権限など、複数の権限が必要です。権限不足による削除失敗を防ぐために、管理者に連絡して RAM ID に AliyunOSSFullAccess 権限を付与することを推奨します。
OSS 課金を停止する方法
Object Storage Service (OSS) のすべての料金を停止するには、ご利用のアカウント内のすべてのバケットを削除する必要があります。空であってもバケットが 1 つでも存在する場合、または未払いの請求書がある場合は、引き続き料金が発生する可能性があります。
削除したバケットを復元する方法
いいえ。バケットの削除は取り消しできない操作です。バケットを削除する前に、必ずデータをバックアップしてください。