Creating a Bucket (SDK for Node.js)
If you have any questions during development, post them on the Issues page of GitHub.
Function
OBS buckets are containers for storing objects you upload to OBS. This API creates a bucket.
When creating a bucket, you can also configure parameters such as the storage class, region, and access control as needed.
Restrictions
- To create a bucket, you must have the obs:bucket:CreateBucket permission. IAM is recommended for granting permissions. For details, see IAM Custom Policies.
- If the endpoint you use when creating a bucket indicates the default region EU-Dublin (eu-west-101), you do not need to specify the region. Otherwise, you must specify the region based on the actual endpoint. For example, if the endpoint you use for initialization is obs.eu-west-101.myhuaweicloud.com, the location you use when creating a bucket must be eu-west-101. Otherwise, status code 400 is returned.
- A maximum of 100 buckets (regardless of regions) can be created for an account. There is no limit on the number and size of objects in a bucket.
- A bucket name must be unique in OBS. If you repeatedly create buckets with the same name in the same region, an HTTP status code 200 will be returned. In other cases, creating a bucket with the same name as an existing bucket will have an HTTP status code 409 returned, indicating that such a bucket already exists.
- The name of a deleted bucket can be reused for another bucket or a parallel file system at least 30 minutes after the deletion.
- Not all regions support the creation of multi-AZ buckets. You can check whether a region allows you to create multi-AZ buckets by referring to Product Pricing Details.
Method
ObsClient.createBucket(params)
Request Parameters
Parameter |
Type |
Mandatory (Yes/No) |
Description |
---|---|---|---|
Bucket |
string |
Yes |
Explanation: Bucket name. Restrictions:
Value range: The value can contain 3 to 63 characters. Default value: None |
Location |
string |
Yes if the OBS service region is not the default region |
Explanation: Region where a bucket is located. Restrictions: If the endpoint used is obs.myhuaweicloud.eu, this parameter is not required. If any other endpoints are used, this parameter is required. Default value: If obs.myhuaweicloud.eu is used as the endpoint and no region is specified, eu-west-101 (the EU-Dublin region) is used by default. |
ACL |
No |
Explanation: An access control list (ACL) that can be pre-defined when creating a bucket. For details about ACLs, see ACLs. Restrictions: None Value range: See Table 2. Default value: private |
|
StorageClass |
No |
Explanation: Bucket storage class that can be specified at bucket creation. Restrictions: None Value range: See StorageClassType. Default value: STANDARD |
|
GrantRead |
string |
No |
Explanation: ID (domain_id) of an account the READ permission is granted to. The account with the READ permission can list objects, multipart uploads, and object versions in the bucket you are creating, as well as obtain bucket metadata. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
GrantWrite |
string |
No |
Explanation: ID (domain_id) of an account the WRITE permission is granted to. The account with the WRITE permission can create, delete, and overwrite objects in the bucket you are creating; initiate or abort multipart uploads; and upload, copy, and assemble parts. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
GrantReadACP |
string |
No |
Explanation: ID (domain_id) of an account the READ_ACP permission is granted to. The account with the READ_ACP permission can read the ACL of the bucket you are creating. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
GrantWriteACP |
string |
No |
Explanation: ID (domain_id) of an account the WRITE_ACP permission is granted to. The account with the WRITE_ACP permission can modify the ACL of the bucket you are creating. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
GrantFullControl |
string |
No |
Explanation: ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission can perform any operation on the bucket you are creating. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
GrantReadDelivered |
string |
No |
Explanation: ID (domain_id) of an account the READ permission is granted to. By default, this READ permission applies to all objects in the bucket. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
GrantFullControlDelivered |
string |
No |
Explanation: ID (domain_id) of an account the FULL_CONTROL permission is granted to. The account with the FULL_CONTROL permission has full control over the bucket you are creating. By default, the FULL_CONTROL permission applies to all objects in the bucket. Restrictions: None Value range: To obtain the account ID, see How Do I Get My Account ID and User ID? (SDK for Node.js). Default value: None |
MultiEnterprise |
string |
No |
Explanation: Enterprise project ID that can be specified during bucket creation. If you have enabled EPS, you can obtain the project ID from the EPS console. Restrictions: The value of epid is a UUID. epid is not required if you have not enabled EPS yet. Example: 9892d768-2d13-450f-aac7-ed0e44c2585f Default value: None |
AzRedundancy |
string |
No |
Explanation: Data redundancy type that can be specified at bucket creation. Restrictions: Multi-AZ redundancy is not available for Archive storage. If the region where the bucket is located does not support multi-AZ storage, single-AZ storage is used by default. Value range:
Default value: single AZ |
Constant |
Default Value |
Description |
---|---|---|
ObsClient.enums.AclPrivate |
private |
Private read and write A bucket or object can only be accessed by its owner. |
ObsClient.enums.AclPublicRead |
public-read |
Public read and private write If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket. If this permission is granted on an object, everyone can obtain the content and metadata of the object. |
ObsClient.enums.AclPublicReadWrite |
public-read-write |
Public read and write If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart upload tasks. If this permission is granted on an object, everyone can obtain the content and metadata of the object. |
ObsClient.enums.AclPublicReadDelivered |
public-read-delivered |
Public read on a bucket as well as the objects in the bucket. If this permission is granted on a bucket, anyone can read the object list, multipart tasks, metadata, and object versions and read the content and metadata of objects in the bucket.
NOTE:
AclPublicReadDelivered does not apply to objects. |
ObsClient.enums.AclPublicReadWriteDelivered |
public-read-write-delivered |
Public read and write on a bucket as well as the objects in the bucket. If this permission is granted on a bucket, anyone can read the object list, multipart uploads, metadata, and object versions in the bucket and can upload or delete objects, initiate multipart upload tasks, upload parts, assemble parts, copy parts, and abort multipart uploads. They can also read the content and metadata of objects in the bucket.
NOTE:
AclPublicReadWriteDelivered does not apply to objects. |
ObsClient.enums.AclBucketOwnerFullControl |
bucket-owner-full-control |
If this permission is granted on an object, only the bucket and object owners have the full control over the object. By default, if you upload an object to a bucket of any other user, the bucket owner does not have the permissions on your object. After you grant this policy to the bucket owner, the bucket owner can have full control over your object. For example, if user A uploads object x to user B's bucket, user B does not have the control over object x. If user A sets the bucket-owner-full-control policy for object x, user B then has the control over object x. |
Constant |
Default Value |
Description |
---|---|---|
ObsClient.enums.StorageClassStandard |
STANDARD |
Standard storage class. Features low access latency and high throughput and is used for storing massive, frequently accessed (multiple times a month) or small objects (< 1 MB) requiring quick response. |
ObsClient.enums.StorageClassWarm |
WARM |
Infrequent Access storage class. Used for storing data that is semi-frequently accessed (fewer than 12 times a year) but becomes instantly available when needed. |
ObsClient.enums.StorageClassCold |
COLD |
Archive storage class. Used for storing rarely accessed (once a year) data. |
Responses
Type |
Description |
---|---|
NOTE:
This API returns a Promise response, which requires the Promise or async/await syntax. |
Explanation: Returned results. For details, see Table 5. |
Parameter |
Type |
Description |
---|---|---|
CommonMsg |
Explanation: Common information generated after an API call is complete, including the HTTP status code and error code. For details, see Table 6. |
|
InterfaceResult |
Explanation: Results outputted for a successful call. For details, see Table 7. Restrictions: This parameter is not included if the value of Status is greater than 300. |
Parameter |
Type |
Description |
Status |
number |
Explanation: HTTP status code returned by the OBS server. Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For details, see Status Codes. |
Code |
string |
Explanation: Error code returned by the OBS server. |
Message |
string |
Explanation: Error description returned by the OBS server. |
HostId |
string |
Explanation: Request server ID returned by the OBS server. |
RequestId |
string |
Explanation: Request ID returned by the OBS server. |
Id2 |
string |
Explanation: Request ID2 returned by the OBS server. |
Indicator |
string |
Explanation: Error code details returned by the OBS server. |
Code Examples
This example creates a bucket named examplebucket.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
// Import the OBS library. // Use npm to install the client. const ObsClient = require("esdk-obs-nodejs"); // Use the source code to install the client. // var ObsClient = require('./lib/obs'); // Create an ObsClient instance. const obsClient = new ObsClient({ // Obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. Using hard coding may result in leakage. // Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/eu/usermanual-ca/ca_01_0003.html. access_key_id: process.env.ACCESS_KEY_ID, secret_access_key: process.env.SECRET_ACCESS_KEY, // (Optional) If you use a temporary AK/SK pair and a security token to access OBS, you are advised not to use hard coding, which may result in information leakage. You can obtain an AK/SK pair using environment variables or import an AK/SK pair in other ways. // security_token: process.env.SECURITY_TOKEN, // Enter the endpoint corresponding to the region where the bucket is located. EU-Dublin is used here in this example. Replace it with the one currently in use. server: "https://obs.eu-west-101.myhuaweicloud.eu" }); async function createBucket() { try { const params = { // Specify the bucket name. Bucket: "examplebucket", // Specify the region where the bucket is to be created. The region must be the same as that in the passed endpoint. eu-west-101 is used in this example. // Location: "eu-west-101", // Specify an access control policy for the bucket. obs.AclPrivate (private read and write) is used in this example. ACL: obsClient.enums.AclPrivate, // Specify the storage class of the bucket. obs.StorageClassWarm (Infrequent Access) is used as an example. If this parameter is not specified, the bucket is created with the Standard storage class. StorageClass: obsClient.enums.StorageClassWarm, // Specify the AZ type for the bucket. If this parameter is not specified, or it is specified but the involved region does not support multi-AZ storage, single-AZ storage is applied. 3az is used in this example. AzRedundancy: "3az", }; // Create a bucket. const result = await obsClient.createBucket(params); if (result.CommonMsg.Status <= 300) { console.log("Create bucket(%s) successful!", params.Bucket); console.log("RequestId: %s", result.CommonMsg.RequestId); return; }; console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); console.log("Status: %d", result.CommonMsg.Status); console.log("Code: %s", result.CommonMsg.Code); console.log("Message: %s", result.CommonMsg.Message); console.log("RequestId: %s", result.CommonMsg.RequestId); } catch (error) { console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); console.log(error); }; }; createBucket(); |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.