Managing bucket versioning
Bucket versioning enables keeping a history of an object through its versions.
Note
You cannot disable versioning once you enable it; however, you can pause the creation of new versions. After you pause versioning, new objects will be saved as null
versions.
To enable bucket versioning:
- In the management console
, select Object Storage from the list of services. - Click the name of the bucket in question.
- In the left-hand panel, select
Settings. - Select the Versioning tab.
- To enable or pause versioning, use Status.
- Click Save.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameters.
-
See the description of the CLI command for editing a bucket ACL:
yc storage bucket update --help
-
Run this command:
yc storage bucket update --name <bucket_name> --versioning versioning-enabled
Result:
name: my-bucket folder_id: csgeoelk7fl15******** default_storage_class: STANDARD versioning: VERSIONING_ENABLED max_size: "10737418240" acl: {} created_at: "2022-12-14T08:42:16.273717Z"
If you do not have the AWS CLI yet, install and configure it.
Run this command:
aws --endpoint https://storage.yandexcloud.net \
s3api put-bucket-versioning \
--bucket <bucket_name> \
--versioning-configuration 'Status=Enabled'
Note
Terraform uses a service account to interact with Object Storage. Assign to the service account the required role, e.g., storage.admin
, for the folder where you are going to create resources.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
Retrieve static access keys: a secret key and key ID used for Object Storage authentication.
Note
In addition to static access keys, you can use an IAM token for authentication in Object Storage. For more details, see Creating a bucket and the relevant provider documentation
In the configuration file, define the parameters of the resources you want to create:
resource "yandex_iam_service_account" "sa" {
name = "<service_account_name>"
}
// Assigning a role to a service account
resource "yandex_resourcemanager_folder_iam_member" "sa-admin" {
folder_id = "<folder_ID>"
role = "storage.admin"
member = "serviceAccount:${yandex_iam_service_account.sa.id}"
}
// Creating a static access key
resource "yandex_iam_service_account_static_access_key" "sa-static-key" {
service_account_id = yandex_iam_service_account.sa.id
description = "static access key for object storage"
}
resource "yandex_storage_bucket" "b" {
bucket = "<bucket_name>"
access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key
secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key
acl = "private"
versioning {
enabled = true
}
}
Where:
bucket
: Bucket name. This is a required parameter.access_key
: Static access key ID.secret_key
: Secret access key value.acl
: ACL policy to apply. The default value isprivate
. This is an optional parameter.versioning
: Managing bucket versioning:enabled
: Enables bucket versioning. This is an optional parameter.
To manage bucket versioning, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the putBucketVersioning S3 API method.