Create an OSS on CloudBox bucket

Updated at:

OSS on CloudBox lets you monitor and process your local data. It is ideal for use cases that require low latency or unified management of multiple branch offices. Before you use OSS on CloudBox, you must first create an OSS on CloudBox bucket.

Prerequisites

  • OSS on CloudBox is available only in the China (Hangzhou), China (Shanghai), China (Shenzhen), China (Heyuan), China (Beijing), and China (Chengdu) regions.

  • You have purchased a CloudBox.

  • You have created a VPC and a vSwitch for the CloudBox.

  • You have contacted technical support to request a SingleTunnel network type for your CloudBox's VPC.

Procedure

OSS console

  1. Log on to the OSS console.

  2. In the left-side navigation pane, choose Data Service > OSS on CloudBox Buckets, and then click Create Bucket.

  3. On the Create Bucket page, set the following parameters and click Create.

    Parameter

    Description

    Bucket Name

    Enter a name for the bucket. The name must meet the following requirements:

    • The bucket name must be unique within the CloudBox.

    • The name can contain only lowercase letters, digits, and hyphens (-).
    • The name must start and end with a lowercase letter or a digit.
    • The name must be 3 to 63 characters in length.

    Region

    Select the region where your purchased CloudBox is located.

    Endpoint

    After you select a region and a Cloud Box ID, an endpoint is automatically assigned to the bucket. OSS on CloudBox provides two types of endpoints: a control endpoint in the <Cloudbox-Id>.<Region>.oss-cloudbox-control.aliyuncs.com format and a data endpoint in the <Cloudbox-Id>.<Region>.oss-cloudbox.aliyuncs.com format.

    Storage Class

    Only Standard is supported.

    Redundancy Type

    Only LRS is supported.

    ACL (Access Control List)

    Select the ACL for objects in the bucket.

    • Private: Only the bucket owner can perform read and write operations on objects in the bucket. Other users cannot access the objects in the bucket.
    • Public Read: Only the bucket owner can perform write operations on objects in the bucket. Other users, including anonymous users, can perform only read operations on the objects in the bucket.
      Warning All users on the Internet can access the objects in the bucket. This may result in unexpected access to the data in your bucket and unexpectedly high fees. Exercise caution when you set your bucket ACL to Public Read.
    • Public Read/Write: All users, including anonymous users, can perform read and write operations on the objects in the bucket.
      Warning All users on the Internet can access objects in the bucket and write data to the bucket. This may result in unexpected access to the data in your bucket and unexpectedly high fees. If a user uploads prohibited data or information, your legitimate interests and rights may be infringed. We recommend that you do not set your bucket ACL to Public Read/Write except in special cases.

    Cloud Box ID

    Select your CloudBox ID.

    Versioning

    Select whether to enable versioning.

    • Activate: If you enable versioning for a bucket, objects that are overwritten or deleted in the bucket are stored as previous versions. Versioning allows you to recover objects in a bucket to a previous version, and protects your data from being accidentally overwritten or deleted. For more information, see Versioning.
    • Not Activated: If you disable versioning for a bucket, objects that are overwritten or deleted in the bucket are not recovered.

    Encryption Method

    Select a server-side encryption method.

    • None: Disables server-side encryption.

    • OSS-Managed: OSS encrypts objects by using its own managed keys. For added protection, OSS uses a unique key for each object and encrypts the key itself with a master key for additional protection.

    The only supported Encryption Algorithm is AES256.

Use an Alibaba Cloud SDK

You can create an OSS on CloudBox bucket by using the OSS SDK for Java, Python, or Go (Java SDK 3.15.0 or later, Python SDK V2 1.1.1 or later, or Go SDK V2 v1.2.1 or later). For OSS on CloudBox, the Python and Go SDKs are called in the same way as they are in public cloud OSS. For information about how to create a client, see SDK support.

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;

public class Demo {

    public static void main(String[] args) throws Exception {
        // Specify the data endpoint for the OSS on CloudBox bucket.
        String endpoint = "https://cb-f8z7yvzgwfkl9q0h****.cn-hangzhou.oss-cloudbox.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.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the name of the OSS on CloudBox bucket, for example, examplebucket.
        String bucketName = "examplebucket";
        // Specify the region where the OSS on CloudBox bucket is located.
        String region = "cn-hangzhou";
        // Specify the Cloud Box ID.
        String cloudBoxId = "cb-f8z7yvzgwfkl9q0h****";


        // Create an OSSClient instance.
        // Call shutdown() to release resources when the client is no longer needed.
        ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
        conf.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(new DefaultCredentialProvider(credentialsProvider.getCredentials()))
                .clientConfiguration(conf)
                .region(region)
                .cloudBoxId(cloudBoxId)
                .build();

        try {
            // Create a CreateBucketRequest object.
            CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);            
                       
            // Set the ACL of the OSS on CloudBox bucket to public-read. The default ACL is private.
            //createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);

            // Create the OSS on CloudBox bucket.
            ossClient.createBucket(createBucketRequest);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request reached OSS but was rejected with an error response.");
            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 a 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();
            }
        }
    }
}
import alibabacloud_oss_v2 as oss

# Obtain access credentials from environment variables. Before you run this sample, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

# Use the default configuration of the SDK.
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
# Specify the region where the OSS on CloudBox bucket is located. Example: cn-hangzhou.
cfg.region = "cn-hangzhou"
# Specify the CloudBox ID. After you set the CloudBox ID, the SDK automatically switches the signing product to oss-cloudbox.
cfg.cloud_box_id = "cb-f8z7yvzgwfkl9q0h****"
# Specify the data endpoint of the OSS on CloudBox bucket, in the CloudboxId.Region.oss-cloudbox.aliyuncs.com format.
cfg.endpoint = "cb-f8z7yvzgwfkl9q0h****.cn-hangzhou.oss-cloudbox.aliyuncs.com"

# Create an OSS client.
client = oss.Client(cfg)

# Create an OSS on CloudBox bucket. Specify the bucket name. Example: examplebucket.
result = client.put_bucket(oss.PutBucketRequest(
    bucket="examplebucket"
))

print(f'status code: {result.status_code},'
      f' request id: {result.request_id}')
package main

import (
	"context"
	"log"

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

func main() {
	// Use the default configuration of the SDK and obtain access credentials from environment variables.
	// Before you run this sample, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
	cfg := oss.LoadDefaultConfig().
		WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
		// Specify the region where the OSS on CloudBox bucket is located. Example: cn-hangzhou.
		WithRegion("cn-hangzhou").
		// Specify the data endpoint of the OSS on CloudBox bucket, in the CloudboxId.Region.oss-cloudbox.aliyuncs.com format.
		WithEndpoint("cb-f8z7yvzgwfkl9q0h****.cn-hangzhou.oss-cloudbox.aliyuncs.com").
		// Specify the CloudBox ID. After you set the CloudBox ID, the SDK automatically switches the signing product to oss-cloudbox.
		WithCloudBoxId("cb-f8z7yvzgwfkl9q0h****")

	// Create an OSS client.
	client := oss.NewClient(cfg)

	// Create an OSS on CloudBox bucket. Specify the bucket name. Example: examplebucket.
	request := &oss.PutBucketRequest{
		Bucket: oss.Ptr("examplebucket"),
	}
	result, err := client.PutBucket(context.TODO(), request)
	if err != nil {
		log.Fatalf("failed to put bucket %v", err)
	}
	log.Printf("put bucket result:%#v\n", result)
}

ossutil

To create an OSS on CloudBox bucket with ossutil, see put-bucket.

REST API

For advanced customization, you can call the REST API directly. This requires you to write code to calculate the request signature. For more information, see PutBucket.