Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Delete a bucket to stop billing

Son Güncelleme:Oct 15, 2026

Bir pakete artık ihtiyacınız yoksa, tüm faturalandırmayı durdurmak için paketi silebilirsiniz. Object Storage Service (OSS) ücretleri paket içindeki kaynaklar üzerinden alındığından, paketi silmeden önce tüm kaynakları temizlemeniz gerekir. Paketi silmek, gözden kaçan faturalandırılabilir kaynaklardan kaynaklanan beklenmeyen ücretleri önlemenin en güvenilir yoludur. Bir paket silindiğinde verilerin kurtarılamayacağını ve paket adı serbest bırakıldıktan sonra başka bir kullanıcı tarafından alınabileceğini unutmayın. OSS kullanımını tamamen sonlandırmak için hesabınızdaki tüm paketleri silmeniz gerekir.

image

Silme işleminden önce riskleri değerlendirin

  • Geri alınamayan veri kaybı riski

    Bu işlem geri alınamaz; tüm nesneleri, önceki sürümlerini ve parçalarını kalıcı olarak kaldırır. Önceden verilerinizi yedekleyin.

  • Hizmet kesintisi riski

    Bir paketi silmek, ona bağlı olan web sitelerini, uygulamaları veya CDN hizmetlerini anında kesintiye uğratır. Hiçbir hizmetin pakete aktif olarak erişmediğinden emin olun.

  • Paket adı kapma riski

    Bir paket silindikten sonra, adı serbest bırakılmadan önce 4 ila 8 saatlik bir bekleme süresine girer. Adı ayırtmanız gerekiyorsa, paketi silmek yerine boşaltmanızı öneririz.

  • Eş zamanlı silme riski

    Bölgeler arası çoğaltma veya aynı bölge çoğaltmayı etkinleştirdiyseniz, silme işlemi hedef paketteki verileri de temizleyebilir. Yapılandırmanızı kontrol edin.

  • Maliyet ve süre tahmini

    Çok sayıda nesneyi temizlemek API isteği ücretlerine neden olabilir ve veri hacmine bağlı olarak birkaç saat veya daha uzun sürebilir.

Silinmesi gereken kaynakları kontrol edin

Nesneler, parçalar, erişim noktaları, hızlandırıcılar veya RTMP alma URL'leri gibi kaynaklar içeren bir paketi silmeye çalışırsanız, sistem "The bucket is not empty" hatası bildirir. OSS konsolundaki silme sihirbazını kullanmanızı öneririz; bu sihirbaz, temizlenmesi gereken tüm öğeleri otomatik olarak tarar ve listeler.

  1. OSS konsoluna giriş yapın.

  2. Sol gezinme bölmesinde, Buckets seçeneğine tıklayın. Görüntülenen sayfada, hedef paketin adına tıklayın.

  3. Sol gezinme bölmesinin en altına inin ve Delete Bucket seçeneğine tıklayın.

  4. Delete Bucket sayfasında, Delete Bucket seçeneğine tıklayın. Ardından temizlenmesi gereken öğeleri görüntüleyebilirsiniz.

Gerekli kaynakları temizleyin

Bir paketi silmek için öncelikle içindeki tüm kaynakları temizlemeniz gerekir. Sistem tarafından belirlenen kaynakları temizleyin. Paket çok sayıda nesne içeriyorsa, temizleme işlemini otomatikleştirmek için yaşam döngüsü kuralı kullanmanızı öneririz.

Nesneler

Nesneler kaynağının durum sütunu HDFS özelliğinin etkin olduğunu gösteriyorsa, önce HDFS nesnelerini temizlemeniz gerekir. Sürüm oluşturma etkinleştirilmişse, Nesneler sayfası hem mevcut hem de tüm önceki sürümleri görüntüler. Bu nedenle, tüm nesneleri seçip silmek tüm sürümleri kaldırır.

OSS nesneleri

OSS konsolu

  1. Delete Bucket sayfasında, Delete Bucket seçeneğine tıklayın, objects kaynağını bulun ve ardından Delete seçeneğine tıklayın.

  2. Tüm nesneleri seçin ve sayfanın alt kısmındaki Permanently Delete seçeneğine tıklayın.

  3. Görüntülenen iletişim kutusunda, OK seçeneğine tıklayın.

ossutil

Mevcut ve önceki sürümler dahil olmak üzere paketteki tüm nesneleri siler.

ossutil rm oss://examplebucket/ -r

Daha fazla örnek için bkz. rm (silme).

HDFS nesneleri

OSS konsolu

  1. object kaynağının Durum sütununda, HDFS arka plan görevini durdurmak için Pause Now seçeneğine tıklayın.

  2. HDFS sekmesine gitmek için Delete seçeneğine tıklayın.

  3. Tüm HDFS dosyaları silinene kadar sırayla Permanently Delete seçeneğine tıklayın.

HDFS kabuk komutları

hdfs dfs -rm -r -skipTrash oss://examplebucket.cn-hangzhou.oss-dls.aliyuncs.com/*

Daha fazla bilgi için bkz. HDFS kabuk komutlarını kullanarak OSS-HDFS hizmeti için yaygın işlemler gerçekleştirme.

Parçalar

Parçalar, tamamlanmamış çok parçalı yüklemeler tarafından oluşturulan nesne parçalarıdır.

OSS konsolu

  1. Delete Bucket sayfasında, Delete Bucket seçeneğine tıklayın, Parts kaynağını bulun ve Delete seçeneğine tıklayın.

  2. Objects sayfasında, Part Management seçeneğine tıklayın.

  3. Parts panelinde, Delete All seçeneğine tıklayın.

  4. İletişim kutusunda, OK seçeneğine tıklayın.

ossutil

Tamamlanmamış veya iptal edilmiş çok parçalı yüklemelerdeki tüm parçaları siler.

ossutil rm oss://examplebucket -m -r -f

Daha fazla bilgi için bkz. rm (silme).

Erişim noktaları

  1. Sol gezinme çubuğunda, Access Point seçeneğine tıklayın.

  2. Her erişim noktası için Delete Access Point seçeneğine tıklayın.

  3. Ekran talimatlarını izleyerek ilgili erişim ilkesini silin.

  4. Erişim ilkesini sildikten sonra erişim noktası listesine dönün. İstendiğinde erişim noktası adını girin ve silmeyi tamamlamak için OK seçeneğine tıklayın.

Hızlandırıcılar

Bir hızlandırıcının silinmesinin yalnızca önbelleğe alınan verilerini temizlediğini unutmayın. OSS paketinde depolanan veriler etkilenmez.

  1. Sol gezinme çubuğunda, Bucket Settings > Accelerator seçeneğine tıklayın.

  2. OSS hızlandırıcı listesinde, Delete sütunundaki Actions seçeneğine tıklayın.

  3. Sayfada istendiğinde hızlandırıcı adını girin ve silmeyi tamamlamak için OK seçeneğine tıklayın.

    image

RTMP alma URL'leri

Bir paketin LiveChannels özelliklerini OSS konsolu veya araçlarıyla görüntüleyemez veya silemezsiniz. Bunun yerine, SDK kullanın veya API çağrısı yapın. Daha fazla bilgi için DeleteLiveChannel API belgelerine bakın. Aşağıdaki örnek kod, belirtilen bir LiveChannel özelliğinin nasıl silineceğini gösterir.

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();
            }
        }
    }
}

Paketi silin

Paketteki tüm kaynakların temizlendiğini onayladıktan sonra paketi silebilirsiniz.

OSS konsolu

  1. Sol gezinme bölmesinin alt kısmında, paket silme sayfasına gitmek için Delete Bucket seçeneğine tıklayın. Ayrıntılı gezinme adımları için bkz. Silinmesi gereken kaynakları kontrol edin.

  2. Delete Bucket seçeneğine tıklayın, istendiğinde paket adını girin ve ardından silmeyi tamamlamak için OK seçeneğine tıklayın.

ossutil

Aşağıdaki komut, examplebucket adlı paketi siler.

ossutil api delete-bucket --bucket examplebucket

Daha fazla bilgi için bkz. delete-bucket.

OSS SDK

Aşağıdaki bölümlerde, yaygın SDK'lar kullanılarak bir paketin nasıl silineceğine ilişkin kod örnekleri sunulmaktadır. Diğer SDK'lar hakkında bilgi için bkz. SDK'ya genel bakış.

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

Aşağıdaki örnek kod, OSS SDK for Python kullanılarak bir paketin nasıl silineceğini gösterir.

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.OperationError 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

Aşağıdaki örnek kod, OSS SDK for Go kullanılarak bir paketin nasıl silineceğini gösterir.

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(&region, "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

Aşağıdaki örnek kod, OSS SDK for PHP kullanılarak bir paketin nasıl silineceğini gösterir.

<?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')

Büyük hacimler için otomatik temizleme

Bir paket çok sayıda nesne (milyonlarca veya daha fazla) içeriyorsa, yaşam döngüsü kuralı yapılandırmak en verimli ve maliyet açısından en uygun temizleme yöntemidir. Bu yaklaşım, sistemi belirli bir süreden sonra paketteki tüm verileri otomatik olarak silmeye yönlendiren bir "süresi dolup sil" kuralı ayarlamayı içerir. Yaşam döngüsü kurallarına aşina değilseniz, bunları önce üretim dışı bir pakette test etmenizi öneririz.

Not: Nesne silme işlemi geri alınamaz. Dikkatli ilerleyin.

Sürüm oluşturma devre dışı

Sürüm oluşturma özelliği devre dışı bırakılmış bir paket için, tüm nesneleri ve parçaları (çok parçalı yüklemelerden birleştirilmemiş parçalar) otomatik ve hızlı bir şekilde temizlemek amacıyla tek bir yaşam döngüsü kuralı yapılandırmanız yeterlidir.

  1. OSS konsoluna giriş yapın, Paketler sayfasına gidin ve ardından hedef paketin adına tıklayın.

  2. Sol gezinme bölmesinde, Content Security > Versioning seçeneklerini belirleyin ve pakette sürüm oluşturmanın devre dışı bırakıldığını onaylayın.

  3. Sol gezinme bölmesinde, Data Management > Lifecycle seçeneklerini belirleyin. Paketteki tüm nesnelerin son değiştirilme tarihinden 1 gün sonra otomatik olarak silinmesini ve 1 günden eski oluşturulan parçaların otomatik olarak temizlenmesini sağlayan bir yaşam döngüsü kuralı yapılandırın.

Sürüm oluşturma etkin

Bir paket için sürüm oluşturma etkinleştirildiğinde, paket mevcut nesne sürümleri, önceki nesne sürümleri, parçalar ve silme işaretçileri içerebilir. Tüm bu öğeleri otomatik ve hızlı bir şekilde temizlemek için tek bir yaşam döngüsü kuralı yapılandırmanız yeterlidir.

  1. OSS konsoluna giriş yapın, Paketler sayfasına gidin ve ardından hedef paketin adına tıklayın.

  2. Sol gezinme çubuğunda, Content Security > Versioning seçeneklerini belirleyin ve pakette sürüm oluşturmanın etkinleştirildiğini onaylayın.

  3. Sol gezinme çubuğunda, Data Management > Lifecycle seçeneklerini belirleyin ve paketteki tüm mevcut ve önceki sürüm nesnelerinin son değişikliklerinden 1 gün sonra otomatik olarak silinmesini ve 1 günden eski oluşturulan parçaların otomatik olarak temizlenmesini sağlayan bir yaşam döngüsü kuralı yapılandırın. Bu kural, silme işaretçilerini de temizler.

SSS

"Bucket not empty" hatası

Bu hata, pakette hala kaynaklar bulunduğunu gösterir. Kalan kaynakları belirlemek ve temizlemek için OSS konsolunu kullanmanızı ve Gerekli kaynakları temizleyin bölümünde açıklanan adımları uygulamanızı öneririz. Ardından, paketi tekrar silmeyi deneyin.

Aynı adla paket yeniden oluşturma

Bir paket silindikten sonra, adı 4 ila 8 saat süren bir bekleme süresine girer. Bu süre boyunca hiçbir kullanıcı bu adla yeni bir paket oluşturamaz. Derhal bir pakete ihtiyacınız varsa, yeni bir ad kullanın.

Bekleme süresi sona erdikten sonra, ad tüm kullanıcılara açık hale gelir. Paketi hemen yeniden oluşturmazsanız, sizden önce başka bir kullanıcı bu adı alabilir.

Birden çok paketin toplu silinmesi

Uyarı

Toplu silme, kalıcı veri kaybına neden olabilecek yüksek riskli bir işlemdir. Devam etmeden önce, silinecek paketlerin listesini dikkatlice doğrulayın ve gerekli tüm verilerin yedeklendiğinden emin olun.

OSS konsolu toplu silmeyi desteklemez. Ancak, bu işlemi gerçekleştirmek için ossutil kullanan bir betik yazabilirsiniz.

Temel mantık aşağıdaki gibidir:

  1. Liste hazırlama: Silmek istediğiniz tüm paketlerin adlarını içeren doğru bir metin dosyası veya liste oluşturun.

  2. Döngü içinde yürütme: Betiğiniz bu listede yineleme yapmalı ve her paket adı için aşağıdaki iki temel adımı gerçekleştirmelidir.

    1. Paketi boşaltma: Geçerli paket için, onu boşaltmak amacıyla ossutil komutunu çağırın.

    2. Boş paketi silme: Önceki adımın başarılı olduğunu onayladıktan sonra, paketi silmek için ossutil komutunu çağırın.

"Insufficient permissions" hatası

Bir paketi silmeden önce, içindeki tüm kaynakları temizlemeniz gerekir. Bu süreç, listeleme ve silme izinleri gibi birden çok izin gerektirir. Eksik izinlerden kaynaklanan silme hatalarını önlemek için, yöneticinizle iletişime geçerek RAM kimliğinize AliyunOSSFullAccess iznini vermesini öneririz.

OSS faturalandırması nasıl durdurulur

Tüm Object Storage Service (OSS) ücretlendirmelerini durdurmak için hesabınızdaki tüm paketleri silmeniz gerekir. Boş olsa bile herhangi bir paket mevcut olduğunda veya ödenmemiş faturalarınız bulunduğunda ücretlendirilmeye devam edebilirsiniz.

Silinen bir paketi kurtarma

Hayır. Paket silme işlemi geri alınamaz. Paketi silmeden önce verilerinizi mutlaka yedekleyin.