All Products
Search
Document Center

Object Storage Service:Delete a vector bucket (Go SDK V2)

Last Updated:Mar 20, 2026

Use the Go SDK V2 to call the DeleteVectorBucket operation and permanently delete a vector bucket.

Warning

This operation is irreversible. Once deleted, the vector bucket and all its data cannot be recovered.

Prerequisites

Before you begin, make sure that you have:

  • Go SDK V2 installed and configured

  • The oss:DeleteVectorBucket permission granted to your identity — Alibaba Cloud accounts have this permission by default; Resource Access Management (RAM) users and RAM roles do not, and must be granted it via a RAM policy or a bucket policy

  • The name and region of the vector bucket to delete

  • The account ID associated with the vector bucket

Method definition

func (c *VectorsClient) DeleteVectorBucket(ctx context.Context, request *DeleteVectorBucketRequest, optFns ...func(*Options)) (*DeleteVectorBucketResult, error)

Parameters

ParameterTypeDescription
ctxcontext.ContextThe request context.
request*DeleteVectorBucketRequestThe request parameters, including the name of the vector bucket to delete. See DeleteVectorBucketRequest.
optFns...func(*Options)(Optional) Interface-level configuration options. See Options.

Return values

ValueTypeDescription
result*DeleteVectorBucketResultThe result of the operation. Valid only when err is nil. See DeleteVectorBucketResult.
errerrorThe error returned if the operation fails. nil on success. Check err != nil to handle failures.

Example

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"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)

var (
	region     string
	bucketName string
	accountId  string
)

func init() {
	flag.StringVar(&region, "region", "", "The region where the vector bucket is located.")
	flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
	flag.StringVar(&accountId, "account-id", "", "The ID of the vector account.")
}

func main() {
	flag.Parse()
	if len(bucketName) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, bucket name required")
	}

	if len(region) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, region required")
	}

	if len(accountId) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, accountId required")
	}

	// Load credentials from environment variables, region and account ID from flags
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId)

	// Initialize the VectorsClient
	client := vectors.NewVectorsClient(cfg)

	// Build the delete request
	request := &vectors.DeleteVectorBucketRequest{
		Bucket: oss.Ptr(bucketName),
	}

	// Call DeleteVectorBucket and handle the result
	result, err := client.DeleteVectorBucket(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to delete vector bucket %v", err)
	}
	log.Printf("delete vector bucket result:%#v\n", result)
}

Run the example with the required flags:

go run main.go --region <region-id> --bucket <bucket-name> --account-id <account-id>

Replace the placeholders with actual values:

PlaceholderDescriptionExample
<region-id>The region where the vector bucket is locatedcn-hangzhou
<bucket-name>The name of the vector bucket to deletemy-vector-bucket
<account-id>The ID of the vector account123456789

References

For the complete sample file, see delete_vector_bucket.go.