All Products
Search
Document Center

Object Storage Service:Get vector bucket information (Go SDK V2)

Last Updated:Mar 20, 2026

Call GetVectorBucket to retrieve information about a vector bucket.

Prerequisites

Before you begin, ensure that you have:

  • The OSS Go SDK V2 installed

  • The oss:GetVectorBucket permission granted via a RAM Policy or a bucket policy

  • AccessKey credentials available as environment variables

By default, an Alibaba Cloud account has full permissions. A Resource Access Management (RAM) user or RAM role has no permissions by default and must be explicitly granted oss:GetVectorBucket.

Permissions

APIActionDescription
GetVectorBucketoss:GetVectorBucketGets information about a vector bucket.

Method definition

func (c *VectorsClient) GetVectorBucket(ctx context.Context, request *GetVectorBucketRequest, optFns ...func(*Options)) (*GetVectorBucketResult, error)

Request parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe request context.
request*GetVectorBucketRequestYesThe request parameters. The Bucket field (type *string) specifies the vector bucket name and is required. For all fields, see GetVectorBucketRequest.
optFns...func(*Options)NoOperation-level configuration overrides. See Options.

Return values

ValueTypeDescription
result*GetVectorBucketResultThe vector bucket information. Valid only when err is nil. See GetVectorBucketResult.
errerrorThe error returned if the operation fails. nil on success.

Sample code

The example below loads credentials from environment variables, builds a VectorsClient, and calls GetVectorBucket with the bucket name, region, and account ID passed as command-line flags.

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 in which 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, accounId required")
	}

	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).WithAccountId(accountId)

	client := vectors.NewVectorsClient(cfg)

	request := &vectors.GetVectorBucketRequest{
		Bucket: oss.Ptr(bucketName),
	}
	result, err := client.GetVectorBucket(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to get vector bucket %v", err)
	}
	log.Printf("get vector bucket result:%#v\n", result)
}

Run the example with:

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

Replace the placeholders with your actual values:

PlaceholderDescriptionExample
<region-id>The region where the vector bucket is located.cn-hangzhou
<bucket-name>The name of the vector bucket.my-vector-bucket
<account-id>The ID of the vector account.1234567890

References