Create
Creates a bucket in the specified folder.
- TypeScript
- Python
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);
}
})();
import os
import grpc
import yandexcloud
from yandex.cloud.storage.v1.bucket_pb2 import ACL
from yandex.cloud.storage.v1.bucket_pb2 import AnonymousAccessFlags
from yandex.cloud.storage.v1.bucket_pb2 import Bucket
from yandex.cloud.storage.v1.bucket_service_pb2_grpc import BucketServiceStub
from yandex.cloud.storage.v1.bucket_service_pb2 import CreateBucketMetadata
from yandex.cloud.storage.v1.bucket_service_pb2 import CreateBucketRequest
from yandex.cloud.storage.v1.bucket_pb2 import Tag
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(BucketServiceStub)
operation = service.Create(
CreateBucketRequest(
name="name",
folder_id="folderId",
# default_storage_class = "defaultStorageClass",
# max_size = 0,
# anonymous_access_flags = AnonymousAccessFlags(
# read = BoolValue(
# value = true
# ),
# list = BoolValue(
# value = true
# ),
# config_read = BoolValue(
# value = true
# )
# ),
# acl = ACL(
# grants = [ACL.Grant(
# permission = Grant.Permission.PERMISSION_FULL_CONTROL,
# grant_type = Grant.GrantType.GRANT_TYPE_ACCOUNT,
# grantee_id = "granteeId"
# )]
# ),
# tags = [Tag(
# key = "key",
# value = "value"
# )]
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=Bucket,
meta_type=CreateBucketMetadata,
)
print(operation_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
, andPERMISSION_READ_ACP
on the bucket. Maps tox-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 forx-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 forx-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 forx-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
, andPERMISSION_READ_ACP
on the bucket. Maps tox-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 forx-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 forx-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 forx-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.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe 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.