Managing bucket object lifecycles
Object Storage enables managing bucket object lifecycles.
Object lifecycles are updated daily at 00:00 UTC. This operation takes a few hours to complete.
-
In the management console
, select Object Storage from the list of services and go to the bucket you want to configure object lifecycles for. -
In the left-hand panel, select
Settings. -
Select the Lifecycle tab.
-
Click Configure.
-
Fill out the form that opens. You can add, delete, and edit configuration rules.
To create a rule:
-
Enable Status. With this option, you can enable or disable a rule without deleting it from a configuration.
-
Fill in the fields as follows:
- Description: Provide the rule description as you see fit.
- Prefix: Portion of the object's key of the required length starting from the beginning of the key. The prefix is used to sort the objects falling within the scope of the rule. If the rule is valid for all objects, leave this field empty.
- Add label: The rule triggers for all objects with the specified labels.
- Maximum size in bytes: The rule triggers for all objects smaller than or matching the specified size.
- Minimum size in bytes: The rule triggers for all objects larger than or matching the specified size.
-
Select and configure the types of actions to be performed with the objects when a rule triggers:
-
Expiration
: Remove any objects from bucket:Number of days
: Triggers as many days after an object was uploaded as specified in the Trigger time field.Exact date
: Triggers on the date specified in the Trigger date field.Deletion marker without noncurrent versions
: Deletes the delete marker for which expired object versions no longer exist.
-
Transition
: Moves any objects from standard (STANDARD
) to cold (COLD
) or ice (ICE
) storage:Number of days
: Triggers as many days after an object was uploaded as specified in the Trigger time field.Exact date
: Triggers on the date specified in the Trigger date field.- Storage class: Type of storage the objects will move to.
-
NoncurrentVersionExpiration
: Remove non-current object versions from the bucket. Triggers as many days after an object's version became non-current as specified in the Trigger time field. -
NoncurrentVersionTransition
: Moves non-current versions of objects from standard (STANDARD
) to cold (COLD
) or ice (ICE
) storage:- Trigger time: Number of days to pass before the rule triggers after an object's version becomes non-current.
- Storage class: Type of storage the objects will move to.
-
AbortIncompleteMultipartUpload
: Remove all parts of failed multipart uploads from the bucket. Triggers as many days after an object was uploaded as specified in the Trigger time field.
-
-
Click Save.
You can add multiple rules at once. To add a new rule, click Add rule and repeat the above steps.
For more information, see Bucket object lifecycle configuration.
-
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 through the --folder-name
or --folder-id
parameter.
-
Define the object lifecycle configuration in JSON format. Here is an example:
{ "lifecycleRules": [ { "id": "DeleteOldBackups", "enabled": true, "filter": { "prefix": "backup/" }, "transitions": [ { "date": "2025-01-01T00:00:00Z", "storage_class": "ICE" } ], "expiration": { "days": "180" } } ] }
The possible configuration parameters include:
-
id
: Unique rule ID which must consist of 255 characters or less. This is an optional parameter. -
enabled
: Rule state. This is a required parameter. -
filter
: Object filter. This is an optional parameter. It may only contain one element of each type:-
prefix
: Object key prefix that identifies one or more objects falling under the rule. The rule applies to objects with the specified key prefix. This is an optional parameter. -
objectSizeGreaterThan
: Minimum object size in bytes. The rule applies to objects with a size greater than or equal to the specified value. This is an optional parameter. -
objectSizeLessThan
: Maximum object size in bytes. The rule applies to objects with a size less than or equal to the specified value. This is an optional parameter. -
tag
: Object label. This is an optional parameter. The rule applies to objects with the specified label assigned. It is provided as a record that contains two key-value pairs, such as the following:"tag": [{"key": "some_key", "value": "some_value"}]
-
andOperator
:AND
logical operator for filters. This is an optional parameter. Use this filter to combine prefix, size, and label filtering in a single rule. WithandOperator
, you can configure filtering by multiple labels at the same time. To do this, specify the labels in thetag
key as an array of objects, each containing two key-value pairs.Here is an example of a filter using
AND
:"filter": { "andOperator": { "prefix": "backup/", "tag": [ { "key": "key_1", "value": "value_1" }, { "key": "key_2", "value": "value_2" } ], "objectSizeGreaterThan": "16", "objectSizeLessThan": "1024" } }
Without a specified object filter, the rule applies to all objects in the bucket.
-
-
transitions
: Parameter of a rule for changing the storage class of any objects from regular (STANDARD
) to cold (COLD
,STANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. It may contain:date
: Date after which you want the rule to take effect, in ISO 8601 format, such asYYYY-MM-DDT00:00:00Z
. The time is always 00:00 UTC. You cannot usedate
together withdays
. This is an optional parameter.days
: Number of days following the object creation date after which the rule will take effect. The minimum value is1
. You cannot usedays
together withdate
. This is an optional parameter.storage_class
: Storage class to move the object to. It can beCOLD
,STANDARD_IA
, orICE
. This is a required parameter.
It is provided as an array, such as follows:
"transitions": [{ "days": "<number_of_days>", "storage_class": "<storage_class>" }]
-
expiration
: Parameter of a rule used to delete any objects. This is an optional parameter. It may contain:date
: Date after which you want the rule to take effect, in ISO 8601 format, such asYYYY-MM-DDT00:00:00Z
. The time is always 00:00 UTC. You cannot usedate
together withdays
. This is an optional parameter.days
: Number of days following the object creation date after which the rule will take effect. The minimum value is1
. You cannot usedays
together withdate
. This is an optional parameter.expired_object_delete_marker
: Removes the delete marker for which expired object versions no longer exist. It can either betrue
orfalse
. This is an optional parameter.
-
noncurrent_transitions
: Parameter of a rule for changing the storage class of non-current object versions from regular (STANDARD
) to cold (COLD
,STANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. It may contain:noncurrent_days
: Number of days before transition. The minimum value is1
. This is a required parameter.storage_class
: Storage class to move the object to. It can beCOLD
,STANDARD_IA
, orICE
. This is a required parameter.
-
noncurrent_expiration
: Parameter of a rule for deleting non-current object versions. This is an optional parameter. It may contain:noncurrent_days
: Number of days before expiration. The minimum value is1
. This is a required parameter.
-
abort_incomplete_multipart_upload_days
: Parameter of a rule for removing all parts of multipart uploads that were not complete within the specified number of days. This is an optional parameter. -
noncurrent_delete_markers
: Parameter of a rule for deleting non-current delete markers. This is an optional parameter. It may contain:noncurrent_days
: Number of days that must elapse after the delete marker version is classified as non-current before the rule takes effect. The minimum value is0
. This is a required parameter.
Make sure to specify at least one of the following parameters:
transitions
,expiration
,noncurrent_transitions
,noncurrent_expiration
, orabort_incomplete_multipart_upload_days
.Once the configuration is complete, save it to a file, e.g.,
lifecycles.json
. -
-
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 list
Result:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Save the
NAME
value for the bucket to configure object lifecycles in. -
Run this command:
yc storage bucket update \ --name <bucket_name> \ --lifecycle-rules-from-file <path_to_configuration_file>
Where:
--name
: Name of the bucket to configure lifecycles in.--lifecycle-rules-from-file
: Path to the lifecycle configuration file.
The configuration specified in the command overrides the current bucket lifecycle settings. You can retrieve the current settings using the
yc storage bucket get <bucket_name> --full
command.
To remove the lifecycle configuration, run this command:
yc storage bucket update \
--name <bucket_name> \
--remove-lifecycle-rules
To upload a configuration using the AWS CLI:
-
Define the object lifecycle configuration in JSON format. Here is an example:
{ "Rules": [ { "ID": "DeleteOldBackups", "Filter": { "Prefix": "backup/" }, "Status": "Enabled", "Transitions": [ { "Date": "2025-01-01", "StorageClass": "ICE" } ], "Expiration": { "Days": 180 } } ] }
The possible configuration parameters include:
-
ID
: Unique rule ID which must consist of 255 characters or less. This is an optional parameter. -
Filter
: Object filter. This is an optional parameter. It may only contain one element of each type:-
Prefix
: Object key prefix. The rule applies to objects with the specified key prefix. This is an optional parameter. -
ObjectSizeGreaterThan
: Minimum object size in bytes. The rule applies to objects with a size greater than or equal to the specified value. This is an optional parameter. -
ObjectSizeLessThan
: Maximum object size in bytes. The rule applies to objects with a size less than or equal to the specified value. This is an optional parameter. -
Tag
: Object label. This is an optional parameter. The rule applies to objects with the specified label assigned. It is provided as a record that contains two key-value pairs, such as the following:"Tag": [{"Key": "some_key", "Value": "some_value"}]
-
And
:AND
logical operator for filters. This is an optional parameter. Use this filter to combine prefix, size, and label filtering in a single rule. WithAnd
, you can configure filtering by multiple labels at the same time. To do this, specify the labels in theTags
key as an array of objects, each containing two key-value pairs.Here is an example of a filter using
AND
:"Filter": { "And": { "Prefix": "backup/", "Tags": [ { "Key": "key_1", "Value": "value_1" }, { "Key": "key_2", "Value": "value_2" } ], "ObjectSizeGreaterThan": 1, "ObjectSizeLessThan": 1024 } }
Without a specified object filter, the rule applies to all objects in the bucket.
-
-
Status
: Rule status. This is a required parameter. It can take one of the following values:Enabled
: Rule enabled.Disabled
: Rule disabled.
-
Transitions
: Parameter of a rule for changing the storage class of any objects from regular (STANDARD
) to cold (COLD
,STANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. It may contain:Date
: Date after which the storage class will change, in ISO 8601 format, such asYYYY-MM-DD
. The time is always 00:00 UTC. You cannot useDate
together withDays
. This is an optional parameter.Days
: Number of days from the object creation date after which the storage class will change. The minimum value is1
. You cannot useDays
together withDate
. This is an optional parameter.StorageClass
: Storage class to move the object to. It can beCOLD
,STANDARD_IA
, orICE
. This is a required parameter.
It is provided as an array, such as follows:
"Transitions": [{ "Days": "<number_of_days>", "StorageClass": "<storage_class>" }]
To set the
Transitions
parameter, you must specify thePrefix
parameter in the configuration file. ThePrefix
value may be empty (""
). -
Expiration
: Parameter of a rule for deleting any objects. This is an optional parameter. It may contain:Date
: Date after which the object will be deleted, in ISO 8601 format, such asYYYY-MM-DD
. The time is always 00:00 UTC. You cannot useDate
together withDays
. This is an optional parameter.Days
: Number of days from the object creation date after which the object will be deleted. The minimum value is1
. You cannot useDays
together withDate
. This is an optional parameter.ExpiredObjectDeleteMarker
: Removes the delete marker for which expired object versions no longer exist. It can either betrue
orfalse
. This is an optional parameter.
-
NoncurrentVersionTransitions
: Parameter of a rule for changing the storage class of non-current object versions from regular (STANDARD
) to cold (COLD
,STANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. It may contain:NoncurrentDays
: Number of days before the storage class of a non-current object version is changed. The minimum value is1
. This is a required parameter.StorageClass
: Storage class to move the object to. It can beCOLD
,STANDARD_IA
, orICE
. This is a required parameter.
To set the
NoncurrentVersionTransitions
parameter, you must specify thePrefix
parameter in the configuration file. ThePrefix
value may be empty (""
). -
NoncurrentVersionExpiration
: Parameter of a rule for deleting non-current object versions. This is an optional parameter.The rule has the required
NoncurrentDays
parameter for the number of days before non-current object version is deleted. The minimum value is1
. -
AbortIncompleteMultipartUpload
: Parameter of a rule for removing all parts of multipart uploads that were not complete within the specified number of days. This is an optional parameter.The rule has the required
DaysAfterInitiation
parameter for the number of days since the upload started. The minimum value is1
.
Specify at least one of the following parameters:
Transitions
,Expiration
,NoncurrentVersionTransition
,NoncurrentVersionExpiration
, orAbortIncompleteMultipartUpload
.Once the configuration is complete, save it to a file, e.g.,
lifecycles.json
. -
-
Upload the configuration to the bucket, e.g.,
backup-bucket
:aws s3api put-bucket-lifecycle-configuration \ --bucket backup-bucket \ --endpoint-url=https://storage.yandexcloud.net \ --lifecycle-configuration file://lifecycles.json
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.
-
In the configuration file, define the parameters of the resources you want to create:
provider "yandex" { cloud_id = "<cloud_ID>" folder_id = "<folder_ID>" zone = "<availability_zone>" token = "<OAuth_token>" } 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" "bucket" { bucket = "<bucket_name>" acl = "private" 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 lifecycle_rule { id = "log" enabled = true filter { tag { key = "some_key" value = "some_value" } } transition { days = 30 storage_class = "COLD" } expiration { days = 90 } } lifecycle_rule { id = "backup" enabled = true filter { and { prefix = "backup/" tags = { key1 = "value1" key2 = "value2" } } } expiration { date = "2020-12-21" } } } resource "yandex_storage_bucket" "versioning_bucket" { bucket = "<bucket_name>" acl = "private" 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 versioning { enabled = true } lifecycle_rule { enabled = true filter { prefix = "config/" } noncurrent_version_transition { days = 30 storage_class = "ICE" } noncurrent_version_expiration { days = 90 } } }
Where:
bucket
: Bucket name. This is a required parameter.access_key
: Static access key ID.secret_key
: Secret access key value.
lifecycle_rule
parameters:-
id
: Unique rule ID which must consist of 255 characters or less. This is an optional parameter. -
filter
: Object filter. This is an optional parameter. It may only contain one element of each type:-
prefix
: Object key prefix that identifies one or more objects falling under the rule. This is an optional parameter. -
object_size_greater_than
: Minimum object size in bytes. The rule applies to objects with a size greater than or equal to the specified value. This is an optional parameter. -
object_size_less_than
: Maximum object size in bytes. The rule applies to objects with a size less than or equal to the specified value. This is an optional parameter. -
tag
: Object label. This is an optional parameter. The rule applies to objects with the specified label assigned. It is provided as a record that contains two key-value pairs, such as the following:tag { key = "some_key" value = "some_value" }
-
And
:AND
logical operator for filters. This is an optional parameter. Use this filter to combine prefix, size, and label filtering in a single rule. WithAnd
, you can configure filtering by multiple labels at the same time. To do this, specify the labels askey = value
pairs in thetags
section.filter { and { prefix = "backup/" tags = { key1 = "value1" key2 = "value2" } object_size_greater_than = 1 object_size_less_than = 1024 } }
Without a specified object filter, the rule applies to all objects in the bucket.
-
-
enabled
: Rule state. This is a required parameter. -
abort_incomplete_multipart_upload_days
: Parameter of a rule for removing all parts of multipart uploads that were not complete within the specified number of days. This is an optional parameter. -
expiration
: Parameter of a rule used to delete any objects. This is an optional parameter. -
transition
: Parameter of a rule for changing the storage class of any objects from regular (STANDARD
) to cold (COLD
,STANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. -
noncurrent_version_expiration
: Parameter of a rule for deleting non-current object versions. This is an optional parameter. -
noncurrent_version_transition
: Parameter of a rule for changing the storage class of non-current object versions from regular (STANDARD
) to cold (COLD
,STANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter.
Make sure to specify at least one of the following parameters:
abort_incomplete_multipart_upload_days
,expiration
,transition
,noncurrent_version_expiration
, ornoncurrent_version_transition
.expiration
parameters:date
: Date after which you want the rule to take effect, You cannot usedate
together withdays
. This is an optional parameter.days
: Number of days following the object creation date after which the rule will take effect. The minimum value is1
. You cannot usedays
together withdate
. This is an optional parameter.expired_object_delete_marker
: Removes the delete marker for which expired object versions no longer exist. It can either betrue
orfalse
. This is an optional parameter.
transition
parameters:date
: Date after which you want the rule to take effect, You cannot usedate
together withdays
. This is an optional parameter.days
: Number of days following the object creation date after which the rule will take effect. The minimum value is1
. You cannot usedays
together withdate
. This is an optional parameter.storage_class
: Storage class to move the object to. It can beCOLD
,STANDARD_IA
, orICE
. This is a required parameter.
noncurrent_version_expiration
parameters:days
: Number of days before expiration. The minimum value is1
. This is a required parameter.
noncurrent_version_transition
parameters:days
: Number of days before transition. The minimum value is1
. This is a required parameter.storage_class
: Storage class to move the object to. It can beCOLD
,STANDARD_IA
, orICE
. This is a required parameter.
For more information about the resources you can create with Terraform, see this provider reference
. -
Make sure the configuration files are correct.
-
In the command line, go to the directory where you created the configuration file.
-
Run a check using this command:
terraform plan
If you described the configuration correctly, the terminal will display a list of the resources being created and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply
-
Confirm creating the resources.
This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console
. -
To manage bucket object lifecycles, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the upload S3 API method.
If you are using the S3 API, specify the lifecycle configuration in XML format.