Skip to main content

Create

Creates a bucket in the specified folder.

import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";

const Bucket = cloudApi.storage.bucket.Bucket;
const CreateBucketRequest = cloudApi.storage.bucket_service.CreateBucketRequest;
const Grant_GrantType = cloudApi.storage.bucket.Grant_GrantType;
const Grant_Permission = cloudApi.storage.bucket.Grant_Permission;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.BucketServiceClient);

const operation = await client.create(
CreateBucketRequest.fromPartial({
name: "name",
folderId: "folderId",
// defaultStorageClass: "defaultStorageClass",
// maxSize: 0,
// anonymousAccessFlags: {
// read: {
// value: true
// },
// list: {
// value: true
// },
// configRead: {
// value: true
// }
// },
// acl: {
// grants: [{
// permission: Grant_Permission.PERMISSION_FULL_CONTROL,
// grantType: Grant_GrantType.GRANT_TYPE_ACCOUNT,
// granteeId: "granteeId"
// }]
// },
// tags: [{
// key: "key",
// value: "value"
// }]
})
);
const finishedOp = await waitForOperation(operation, session);

if (finishedOp.response) {
const result = decodeMessage<typeof Bucket>(finishedOp.response);
console.log(result);
}
})();

CreateBucketRequest​

name : string​

Name of the bucket.

The name must be unique within the platform. For naming limitations and rules, see documentation.

folderId : string​

ID of the folder to create a bucket in.

To get the folder ID, make a yandex.cloud.resourcemanager.v1.FolderService.List request.

defaultStorageClass : string​

Default storage class for objects in the bucket. Supported classes are standard storage (STANDARD), cold storage (COLD, STANDARD_IA, NEARLINE all synonyms), and ice storage (ICE and GLACIER are synonyms). For details, see documentation.

maxSize : int64​

Maximum size of the bucket. For details, see documentation.

anonymousAccessFlags : AnonymousAccessFlags​

Flags for configuring public (anonymous) access to the bucket's content and settings. For details, see documentation.

acl : ACL​

Access control list (ACL) of the bucket. For details, see documentation.

tags : Tag​

List of tags for the bucket. For details, see documentation.

AnonymousAccessFlags​

read : google.protobuf.BoolValue​

Specifies whether public (anonymous) access to read objects in the bucket is enabled.

list : google.protobuf.BoolValue​

Specifies whether public (anonymous) access to the list of objects in the bucket is enabled.

configRead : google.protobuf.BoolValue​

Specifies whether public (anonymous) access to read CORS, static website hosting, and object lifecycles settings of the bucket is enabled.

ACL​

Grant​

A grant resource, used to specify the permission granted and the grantee.

Permission​
  • PERMISSION_UNSPECIFIED

  • PERMISSION_FULL_CONTROL

    Allows grantee the PERMISSION_WRITE, PERMISSION_WRITE_ACP, PERMISSION_READ, and PERMISSION_READ_ACP on the bucket. Maps to x-amz-grant-full-control header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_WRITE

    Allows grantee to create new objects in the bucket. For the bucket and object owners of existing objects, also allows deletions and overwrites of those objects. Maps to x-amz-grant-write header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_WRITE_ACP

    Allows grantee to write the ACL for the bucket. Maps to x-amz-grant-write-acp header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_READ

    Allows grantee to list the objects in the bucket. Maps to x-amz-grant-read header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_READ_ACP

    Allows grantee to read the bucket ACL Maps to x-amz-grant-read-acp header for bucketPutAcl method of Amazon S3-compatible HTTP API.

GrantType​
  • GRANT_TYPE_UNSPECIFIED

  • GRANT_TYPE_ACCOUNT

    A grantee is an account on the platform. For this grantee type, you need to specify the user ID in [Bucket.acl.grants.grantee_id][2] field. To get user ID, see instruction. Maps to using id="*" value for x-amz-grant-* header (bucketPutAcl method of Amazon S3-compatible HTTP API).

  • GRANT_TYPE_ALL_AUTHENTICATED_USERS

    Grantees are all authenticated users, both from your clouds and other users' clouds. Access permission to this group allows any account on the platform to access the resource via a signed (authenticated) request. Maps to using uri="http://acs.amazonaws.com/groups/global/AuthenticatedUsers" value for x-amz-grant-* header (bucketPutAcl method of Amazon S3-compatible HTTP API).

  • GRANT_TYPE_ALL_USERS

    Grantees are all internet users. Access permission to this group allows anyone in the world access to the resource via signed (authenticated) or unsigned (anonymous) requests. Maps to using uri="http://acs.amazonaws.com/groups/global/AllUsers" value for x-amz-grant-* header (bucketPutAcl method of Amazon S3-compatible HTTP API).

permission : Permission​

Permission granted by the grant.

grantType : GrantType​

The grantee type for the grant.

granteeId : string​

ID of the account who is a grantee. Required when the grant_type is GRANT_TYPE_ACCOUNT.

grants : Grant​

List of permissions granted and the grantees.

Tag​

key : string​

Key of the bucket tag.

value : string​

Value of the bucket tag.

Grant​

A grant resource, used to specify the permission granted and the grantee.

Permission​
  • PERMISSION_UNSPECIFIED

  • PERMISSION_FULL_CONTROL

    Allows grantee the PERMISSION_WRITE, PERMISSION_WRITE_ACP, PERMISSION_READ, and PERMISSION_READ_ACP on the bucket. Maps to x-amz-grant-full-control header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_WRITE

    Allows grantee to create new objects in the bucket. For the bucket and object owners of existing objects, also allows deletions and overwrites of those objects. Maps to x-amz-grant-write header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_WRITE_ACP

    Allows grantee to write the ACL for the bucket. Maps to x-amz-grant-write-acp header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_READ

    Allows grantee to list the objects in the bucket. Maps to x-amz-grant-read header for bucketPutAcl method of Amazon S3-compatible HTTP API.

  • PERMISSION_READ_ACP

    Allows grantee to read the bucket ACL Maps to x-amz-grant-read-acp header for bucketPutAcl method of Amazon S3-compatible HTTP API.

GrantType​
  • GRANT_TYPE_UNSPECIFIED

  • GRANT_TYPE_ACCOUNT

    A grantee is an account on the platform. For this grantee type, you need to specify the user ID in [Bucket.acl.grants.grantee_id][4] field. To get user ID, see instruction. Maps to using id="*" value for x-amz-grant-* header (bucketPutAcl method of Amazon S3-compatible HTTP API).

  • GRANT_TYPE_ALL_AUTHENTICATED_USERS

    Grantees are all authenticated users, both from your clouds and other users' clouds. Access permission to this group allows any account on the platform to access the resource via a signed (authenticated) request. Maps to using uri="http://acs.amazonaws.com/groups/global/AuthenticatedUsers" value for x-amz-grant-* header (bucketPutAcl method of Amazon S3-compatible HTTP API).

  • GRANT_TYPE_ALL_USERS

    Grantees are all internet users. Access permission to this group allows anyone in the world access to the resource via signed (authenticated) or unsigned (anonymous) requests. Maps to using uri="http://acs.amazonaws.com/groups/global/AllUsers" value for x-amz-grant-* header (bucketPutAcl method of Amazon S3-compatible HTTP API).

permission : Permission​

Permission granted by the grant.

grantType : GrantType​

The grantee type for the grant.

granteeId : string​

ID of the account who is a grantee. Required when the grant_type is GRANT_TYPE_ACCOUNT.

Operation​

An Operation resource. For more information, see Operation.

id : string​

ID of the operation.

description : string​

Description of the operation. 0-256 characters long.

createdAt : google.protobuf.Timestamp​

Creation timestamp.

createdBy : string​

ID of the user or service account who initiated the operation.

modifiedAt : google.protobuf.Timestamp​

The time when the Operation resource was last modified.

done : bool​

If the value is false, it means the operation is still in progress. If true, the operation is completed, and either error or response is available.

metadata : google.protobuf.Any​

Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.

One of result​

The operation result. If done == false and there was no failure detected, neither error nor response is set. If done == false and there was a failure detected, error is set. If done == true, exactly one of error or response is set.

  • error : google.rpc.Status​

    The error result of the operation in case of failure or cancellation.

  • response : google.protobuf.Any​
    The normal response of the operation in case of success.

    If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.