Limiting the maximum size of a bucket
Object Storage enables limiting the maximum bucket size.
For example, if your service enables users to upload objects to Object Storage, then, by limiting the maximum size, you can better manage user actions and avoid unnecessary costs.
-
In the management console
, select Object Storage from the list of services and go to the bucket whose maximum size you want to limit. -
In the left-hand panel, select
Settings. -
Select the General tab.
-
Set the value of the Max size field.
If the value is
0, the size is not limited. It is similar to the enabled No limit option. -
Click Save.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
See the description of the CLI command for updating a bucket:
yc storage bucket update --help -
Get a list of buckets in the default folder:
yc storage bucket listResult:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+ -
Save the name (from the
NAMEcolumn) of the bucket whose size you want to limit. -
Limit the maximum size of the bucket:
yc storage bucket update \ --name <bucket_name> \ --max-size <maximum_bucket_size>Where:
--name: Name of the bucket whose size you want to limit.--max-size: Maximum bucket size, in bytes (0for unlimited).
Result:
name: first-bucket older_id: b1gmit33ngp6******** default_storage_class: STANDARD versioning: VERSIONING_DISABLED max_size: "26843545600" acl: {} created_at: "2022-12-16T13:58:18.933814Z"
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.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To limit the maximum bucket size:
-
Open the Terraform configuration file and add the
max_sizeparameter to the bucket description:... resource "yandex_storage_bucket" "test" { access_key = "<static_key_ID>" secret_key = "<secret_key>" bucket = "tf-test-bucket" max_size = 1048576 } ...Where:
-
access_key: Static access key ID.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.
-
secret_key: Secret access key value. -
max_size: Maximum bucket size, in bytes.
For more information about
yandex_storage_bucketproperties, see this Terraform article. -
-
Check the configuration using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply -
Confirm the changes: type
yesinto the terminal and press Enter.You can check the bucket update using the management console
.
To limit the maximum bucket size, use the update REST API method for the Bucket resource or the BucketService/Update gRPC API call.