Create Bucket
Updated at:2025-11-03
The following code can be used to create a bucket:
Java
1public void createBucket (BosClient client, String bucketName) {
2 // Create a new bucket
3 client.createBucket(<bucketName>); //Specify bucket name
4}
Note: Since the bucket name is unique across all regions, it is necessary to ensure that the bucketName is not the same as the BucketName on all other regions.
Bucket naming follows the following conventions:
- Only lowercase letters, numbers, and hyphens (-) are allowed.
- Must start with a lowercase letter or a number.
- Length should range between 4-63 bytes.
The bucket created using the above code has private read-write permissions and a standard (Standard) storage class.
- Create a new lcc bucket
The Java SDK supports creating LCC buckets. Users can fill in lcclocation in the request for creating a new bucket. The specific parameters of CreateBucketRequest are as follows:
| Parameters | Types | Description |
|---|---|---|
| bucketTags | String | Bucket tags |
| lccLocation | String | lcc id, used to create an lcc bucket in a specific lcc cluster |
| enableDedicated | Boolean | Used to control the console to enable the lcc recognition allow list |
The following code can be used to create a lcc bucket:
Java
1public void createBucket (BosClient client, String bucketName) {
2 CreateBucketRequest request = new CreateBucketRequest("bucketName");
3 // Set lcc location id
4 request.setLccLocation("lcc id");
5 request.setEnableDedicated(true);
6 client.createBucket(request);
7}
