Create an Agentic Bucket and a Bucket Space

Updated at:

Creating an Agentic Bucket and a Bucket Space is a prerequisite for using the Agentic Bucket service. This topic describes how to create an Agentic Bucket in the OSS console or by calling an API operation, and how to create Bucket Spaces under it.

Prerequisites

Important

The Agentic Bucket feature is available only in the China (Hangzhou), China (Beijing), China (Shanghai), China (Shenzhen), US (Virginia), Japan (Tokyo), and Singapore regions. To use the feature, submit a ticket to apply for activation.

  • You have activated OSS.

  • If you perform the operations as a RAM user, the RAM user is granted the permissions required for Agentic Bucket operations. For information about how to grant permissions to a RAM user, see RAM Policy.

  • If you create Bucket Spaces by calling API operations, you have created an AccessKey pair for signing OSS API requests.

Procedure

The full name of an Agentic Bucket consists of the name prefix that you specify and the -{UID}-{region}-ab-apsr suffix that the system automatically appends. The full name of a Bucket Space consists of the name prefix and the -{UID}-{region}-bs-apsr suffix. The name prefix must be at least 3 characters in length and can contain only lowercase letters, digits, and hyphens, and cannot start or end with a hyphen. The total length of the full name must be 3 to 63 characters. For example, if your account UID is 1234567890123456 and you enter my-agentic as the Agentic Bucket name prefix in the China (Hangzhou) region, the full name of the Agentic Bucket after creation is my-agentic-1234567890123456-cn-hangzhou-ab-apsr.

Step 1: Create an Agentic Bucket

The parameters that you configure when you create an Agentic Bucket, such as the storage class, redundancy type, ACL, versioning, server-side encryption, and Block Public Access, serve as a template for the Bucket Spaces subsequently created under the Agentic Bucket. After the Agentic Bucket is created, you can modify the template parameters by calling the Agentic Bucket property configuration API. The modifications take effect only for Bucket Spaces created after the modifications.

  1. Log on to the OSS console and go to the Agentic Bucket list page.

  2. Click Create Agentic Bucket.

  3. In the Create dialog box, configure the following parameters:

    Parameter

    Description

    Name prefix

    Enter the Agentic Bucket name prefix. The prefix must be at least 3 characters in length and can contain only lowercase letters, digits, and hyphens, and cannot start or end with a hyphen. The system automatically appends the -{UID}-{region}-ab-apsr suffix to form the full name, which cannot exceed 63 characters.

    Region

    Select the region in which the Agentic Bucket resides. The available regions are subject to the options displayed in the console.

    Storage class

    Select the storage class of the Agentic Bucket. Default value: Standard. Valid values: Standard, Infrequent Access, and Archive.

    Redundancy type

    Select the data redundancy type. ZRS (zone-redundant storage) is recommended and used by default. Valid values: ZRS (zone-redundant storage) and LRS (locally redundant storage).

    Read/write permissions (ACL)

    Select the read/write permissions of the Agentic Bucket. Default value: Private. Valid values: Private, Public Read, and Public Read/Write.

    Versioning

    Specify whether to enable versioning. Default value: Disabled. After versioning is enabled, historical versions of data that is overwritten or deleted in a Bucket Space are retained to protect against accidental deletion or overwrite.

    Server-side encryption

    Select the server-side encryption method. Default value: None. Valid values: None, AES256, SM4, and KMS.

    Real-time log query

    Specify whether to enable real-time log query. Default value: Disabled.

    Block Public Access

    Specify whether to enable Block Public Access. Default value: Enabled. After Block Public Access is enabled, public access to all Bucket Spaces under the Agentic Bucket is blocked.

  4. Click OK to complete the creation.

After the Agentic Bucket is created, you can view its endpoints on the Agentic Bucket list page. The endpoints are {full-name}.oss-{region}.aliyuncs.com (Internet) and {full-name}.oss-{region}-internal.aliyuncs.com (internal). These endpoints are used for the management configuration of the Agentic Bucket itself. The OSS Internet endpoint of the Agentic Bucket can be accessed directly.

Step 2: Create a Bucket Space

Bucket Spaces are created under an Agentic Bucket. All configurations of a Bucket Space, including the storage class, redundancy type, ACL, versioning, server-side encryption, and Block Public Access, can be inherited directly from the Agentic Bucket to which it belongs.

Important

You cannot create a Bucket Space when the Agentic Bucket is disabled.

Important

The standard OSS public endpoint of a Bucket Space cannot be accessed directly. You must first bind a custom wildcard domain name to the Agentic Bucket, and then access the Bucket Space through a domain name in the {bucketspace-name}.{base-domain} format.

Console

  1. On the Agentic Bucket list page, click the target Agentic Bucket to go to its Bucket Space management page.

  2. Click Create Bucket Space.

  3. Configure the Bucket Space name. The full name of a Bucket Space ends with -bs-apsr, and the naming constraints are the same as those for an Agentic Bucket. After you confirm the settings, click OK to complete the creation.

API

Call the PutBucket operation. Set Host to the full name of the Bucket Space, and specify the Agentic Bucket to which the Bucket Space belongs by using the x-oss-agentic-bucket request header or query parameter. The request does not accept other PutBucket request headers or a request body. You can call the API operation by using an internal endpoint (initiated from an internal network environment in the same region) or by using a custom wildcard domain name CNAME bound to the Agentic Bucket to which the Bucket Space belongs.

The following is a sample request that uses the header method:

PUT / HTTP/1.1
Host: my-agent-sandbox-1234567890123456-cn-hangzhou-bs-apsr.oss-cn-hangzhou-internal.aliyuncs.com
x-oss-agentic-bucket: my-agentic-1234567890123456-cn-hangzhou-ab-apsr
Date: GMT Date
Authorization: SignatureValue

The following is a sample request that uses the query parameter method:

PUT /?x-oss-agentic-bucket=my-agentic-1234567890123456-cn-hangzhou-ab-apsr HTTP/1.1
Host: my-agent-sandbox-1234567890123456-cn-hangzhou-bs-apsr.oss-cn-hangzhou-internal.aliyuncs.com
Date: GMT Date
Authorization: SignatureValue

If the Bucket Space is created, 200 OK is returned. Common errors include InvalidBucketName (invalid name), AgenticBucketNotFound (the specified Agentic Bucket does not exist), and BucketAlreadyExists (a Bucket Space with the same name already exists).

SDK

You can use an OSS SDK to create a Bucket Space under a specified Agentic Bucket. Code samples for different programming languages are provided as follows.

import com.aliyun.sdk.service.oss2.ClientConfiguration;
import com.aliyun.sdk.service.oss2.OSSClient;
import com.aliyun.sdk.service.oss2.agentic.BucketSpaceClient;
import com.aliyun.sdk.service.oss2.credentials.CredentialsProvider;
import com.aliyun.sdk.service.oss2.credentials.EnvironmentVariableCredentialsProvider;
import com.aliyun.sdk.service.oss2.models.*;

public class BucketSpacePutBucketSample {
    public static void main(String[] args) throws Exception {
        String region = "cn-hangzhou";
        String accountId = "1234567890123456";
        String agenticBucketPrefix = "my-agentic";
        String bucketSpacePrefix = "my-space";

        CredentialsProvider provider = new EnvironmentVariableCredentialsProvider();

        try (OSSClient client = BucketSpaceClient.create(ClientConfiguration.newBuilder()
                .credentialsProvider(provider)
                .region(region)
                .accountId(accountId)
                .build())) {

            PutBucketResult result = client.putBucket(PutBucketRequest.newBuilder()
                    .bucket(bucketSpacePrefix)
                    .agenticBucket(String.format("%s-%s-%s-ab-apsr", agenticBucketPrefix, accountId, region))
                    .build());

            System.out.printf("status code:%d, request id:%s%n",
                    result.statusCode(), result.requestId());

        } catch (Exception e) {
            System.out.printf("error:%n%s", e);
        }
    }
}
import argparse
import alibabacloud_oss_v2 as oss
import alibabacloud_oss_v2.agentic as oss_agentic

# Create a command-line argument parser and describe the script purpose: create a Bucket Space
parser = argparse.ArgumentParser(description="bucket space put bucket sample")

# Define command-line arguments, including the required region, Bucket Space name prefix, account ID,
# the name prefix of the parent Agentic Bucket, and the optional endpoint
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The bucket space prefix name.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--account_id', help='The account id.', required=True)
parser.add_argument('--agentic_bucket', help='The agentic bucket that the bucket space belongs to.', required=True)

def main():
    # Parse the command-line arguments to obtain the user-entered values
    args = parser.parse_args()

    # Load access credentials from environment variables for authentication
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Create a configuration object with the SDK default configuration and set the credentials provider
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Set the region and account ID of the configuration object
    cfg.region = args.region
    cfg.account_id = args.account_id

    # If a custom endpoint is provided, update the endpoint property of the configuration object
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Create a Bucket Space client. This client reuses standard OSS bucket and object operations
    # and automatically resolves the Bucket Space name prefix to the full name {prefix}-{account_id}-{region}-bs-apsr
    client = oss_agentic.BucketSpaceClient.create(cfg)

    # Create a Bucket Space under a specified Agentic Bucket. The bucket parameter of PutBucketRequest
    # is the Bucket Space name prefix, and the agentic_bucket parameter is the full name of the parent Agentic Bucket
    result = client.put_bucket(oss.models.PutBucketRequest(
        bucket=args.bucket,  # The Bucket Space name prefix
        agentic_bucket=f'{args.agentic_bucket}-{args.account_id}-{args.region}-ab-apsr',  # The full name of the Agentic Bucket
    ))

    # Print the status code and request ID of the operation result to confirm the request status
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          )

# When this script is run directly, call the main function to start the processing logic
if __name__ == "__main__":
    main()
package main

import (
	"context"
	"flag"
	"fmt"
	"log"

	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/agentic"
	"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
)

var (
	region        string
	bucket        string
	endpoint      string
	accountId     string
	agenticBucket string
)

func init() {
	flag.StringVar(&region, "region", "", "The region in which the bucket is located.")
	flag.StringVar(&bucket, "bucket", "", "The bucket space prefix name.")
	flag.StringVar(&endpoint, "endpoint", "", "The domain names that other services can use to access OSS.")
	flag.StringVar(&accountId, "account-id", "", "The account id.")
	flag.StringVar(&agenticBucket, "agentic-bucket", "", "The agentic bucket that the bucket space belongs to.")
}

func main() {
	flag.Parse()
	if len(bucket) == 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, account id required")
	}
	if len(agenticBucket) == 0 {
		flag.PrintDefaults()
		log.Fatalf("invalid parameters, agentic bucket name required")
	}

	// Create a configuration object with the SDK default configuration and load access credentials from environment variables
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		WithRegion(region).
		WithAccountId(accountId)
	if len(endpoint) > 0 {
		cfg.WithEndpoint(endpoint)
	}

	// Create a Bucket Space client. This client reuses standard OSS bucket and object operations
	// and automatically resolves the Bucket Space name prefix to the full name {bucket}-{accountId}-{region}-bs-apsr
	client := agentic.NewBucketSpaceClient(cfg)

	// Create a Bucket Space under a specified Agentic Bucket. The Bucket parameter of PutBucketRequest
	// is the Bucket Space name prefix, and the Agentic Bucket parameter is the full name of the parent Agentic Bucket
	request := &oss.PutBucketRequest{
		Bucket:        oss.Ptr(bucket),
		AgenticBucket: oss.Ptr(fmt.Sprintf("%s-%s-%s-ab-apsr", agenticBucket, accountId, region)),
	}
	result, err := client.PutBucket(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to put bucket space %v", err)
	}
	log.Printf("put bucket space result:%#v\n", result)
}
<?php

// Import the autoloader to load the dependencies
require_once __DIR__ . '/../vendor/autoload.php';

use AlibabaCloud\Oss\V2 as Oss;
use AlibabaCloud\Oss\V2\Agentic\BucketSpaceClient;

// Define the command-line argument descriptions, including the required region, Bucket Space name prefix, account ID,
// the name prefix of the parent Agentic Bucket, and the optional endpoint
$optsdesc = [
    "region" => ['help' => 'The region in which the bucket is located.', 'required' => True],
    "endpoint" => ['help' => 'The domain names that other services can use to access OSS.', 'required' => False],
    "account-id" => ['help' => 'The ID of the Alibaba Cloud account that owns the bucket.', 'required' => True],
    "bucket" => ['help' => 'The bucket space prefix name.', 'required' => True],
    "agentic-bucket" => ['help' => 'The agentic bucket that the bucket space belongs to.', 'required' => True],
];
$longopts = \array_map(function ($key) {
    return "$key:";
}, array_keys($optsdesc));
$options = getopt("", $longopts);
foreach ($optsdesc as $key => $value) {
    if ($value['required'] === True && empty($options[$key])) {
        $help = $value['help'];
        echo "Error: the following arguments are required: --$key, $help";
        exit(1);
    }
}

$region = $options["region"];
$accountId = $options["account-id"];
$bucket = $options["bucket"];
$agenticBucket = $options["agentic-bucket"];

// Load access credentials from environment variables for authentication
$credentialsProvider = new Oss\Credentials\EnvironmentVariableCredentialsProvider();

// Create a configuration object with the SDK default configuration. BucketSpaceClient resolves
// the Bucket Space name prefix to the full name automatically: {prefix}-{accountId}-{region}-bs-apsr
$cfg = Oss\Config::loadDefault();
$cfg->setCredentialsProvider($credentialsProvider);
$cfg->setRegion($region);
$cfg->setAccountId($accountId);
if (isset($options["endpoint"])) {
    $cfg->setEndpoint($options["endpoint"]);
}

// Create a Bucket Space client. This client reuses standard OSS bucket and object operations
$client = BucketSpaceClient::newClient($cfg);

try {
    // Create a Bucket Space under a specified Agentic Bucket. The bucket parameter of PutBucketRequest
    // is the Bucket Space name prefix, and the agenticBucket parameter is the full name of the parent Agentic Bucket
    $request = new Oss\Models\PutBucketRequest($bucket);
    $request->agenticBucket = sprintf('%s-%s-%s-ab-apsr', $agenticBucket, $accountId, $region);

    $result = $client->putBucket($request);

    printf(
        'status code: %d' . PHP_EOL . 'request id: %s' . PHP_EOL,
        $result->statusCode,
        $result->requestId
    );
} catch (\Throwable $e) {
    printf("error: %s" . PHP_EOL, $e->getMessage());
    exit(1);
}
import AlibabaCloudOSS
import AlibabaCloudOSSAgentic
import Foundation
import ArgumentParser

@main
struct BucketSpacePutBucket: AsyncParsableCommand {
    func run() async throws {
        do {
            // Set the OSS region
            let region = "cn-hangzhou"

            // Set the Alibaba Cloud account ID
            let accountId = "1234567890123456"

            // Set the name prefix of the parent Agentic Bucket
            let agenticBucketPrefix = "my-agentic"

            // Set the name prefix of the Bucket Space to create
            let bucketSpacePrefix = "my-space"

            // Create a configuration object and set the region and account ID
            let config = Configuration.default()
                .withRegion(region)
                .withCredentialsProvider(EnvironmentCredentialsProvider())
                .withAccountId(accountId)

            // Create a Bucket Space client. This client reuses standard OSS bucket and object operations
            // and automatically resolves the Bucket Space name prefix to the full name:
            // {prefix}-{accountId}-{region}-bs-apsr
            let client = BucketSpaceClient.make(config)

            // Call the putBucket operation to create a Bucket Space under a specified Agentic Bucket.
            // The bucket parameter is the Bucket Space name prefix,
            // and the agenticBucket parameter is the full name of the parent Agentic Bucket
            let result = try await client.putBucket(
                PutBucketRequest(
                    bucket: bucketSpacePrefix,
                    agenticBucket: "\(agenticBucketPrefix)-\(accountId)-\(region)-ab-apsr"
                )
            )

            // Print the request result
            print("PutBucket done, StatusCode:\(result.statusCode), RequestId:\(result.requestId).")
        } catch {
            BucketSpacePutBucket.exit(withError: error)
        }
    }
}

After the Bucket Space is created, you can call the ListBucketSpaces operation to list the Bucket Spaces under the Agentic Bucket, or call the GetBucketInfo operation to view Bucket Space information. The AgenticBucketName field in the response indicates the name of the Agentic Bucket to which the Bucket Space belongs.

The management operations of a Bucket Space, such as configuring the ACL and versioning, and the data operations, such as uploading and downloading objects, are identical to the corresponding operations for a regular bucket. When you call these operations, set Host to the full name of the Bucket Space. You can also reuse the DeleteBucket operation to delete a Bucket Space.

What to do next

For the complete API reference of the Agentic Bucket management operations, see CreateAgenticBucket, GetAgenticBucket, ListAgenticBuckets, PutAgenticBucketStatus, DeleteAgenticBucket, ListBucketSpaces, and Agentic Bucket attribute configuration operations.