Limiting the maximum size of a bucket
Object Storage allows you to limit the maximum size of a bucket.
For example, if you provide the users of your service with the ability to upload objects to Object Storage, then, by limiting the maximum volume, you can better control user actions and avoid unnecessary costs.
-
In the management console
, select a folder. -
Select Object Storage.
-
Click the name of the bucket you need.
-
Go to the Settings tab.
-
Set the value of the Max size field.
If the value is
0
, the maximum size is not limited and is similar to the enabled No limit option. -
Click Save.
If you do not have the Yandex Cloud command line interface 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
parameter.
-
See the description of the CLI command to update a bucket:
yc storage bucket update --help
-
Get a list of buckets in the default folder:
yc storage bucket list
Result:
+------------------+----------------------+----------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+----------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 0 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+----------+-----------------------+---------------------+
-
Using the
NAME
column, save the name of the bucket to limit the size for. -
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 to limit the size for.--max-size
: Maximum bucket size, in bytes (0
for 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.
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To limit the maximum bucket size:
-
Open the Terraform configuration file and add the
max_size
parameter 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.secret_key
: Secret access key value.max_size
: Maximum bucket size, in bytes.
For more information about the
yandex_storage_bucket
resource parameters in Terraform, see the relevant provider documentation . -
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can verify changes to your bucket in 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.