Managing bucket object lifecycles
Object Storage allows managing object lifecycles in a bucket.
Once a day, lifecycles are updated with the latest changes as of 00:00 UTC. This operation takes a few hours to complete.
-
In the management console
, go to the bucket you want to configure object lifecycles for. -
Select Lifecycle.
-
Click Configure.
-
On the page that opens, you can add, remove, 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.
- Maximum size in bytes: Triggers for all objects smaller than or matching the specified size.
- Minimum size in bytes: 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
: Move any objects from theSTANDARD
toCOLD
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.
You can set up the change of the storage class from
STANDARD
toICE
or fromCOLD
orSTANDARD_IA
toICE
using YC CLI, AWS CLI, Terraform, and the API. -
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
: Move non-current object versions fromSTANDARD
toCOLD
storage. Triggers as many days after an object's version became non-current as specified in the Trigger time field.You can set up the change of the storage class from
STANDARD
toICE
or fromCOLD
orSTANDARD_IA
toICE
using YC CLI, AWS CLI, Terraform, and the API. -
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 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.
-
Define the object lifecycle configuration in JSON format. For 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 be 255 characters or less. This is an optional parameter. -
enabled
: Rule status. 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 to which the rule applies. 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 whose size is greater than or equal to the set one. This is an optional parameter. -
objectSizeLessThan
: Maximum object size in bytes. The rule applies to objects whose size is less than or equal to the set one. This is an optional parameter. -
tag
: Object tag. This is an optional parameter. The rule applies to objects to which the specified tag is assigned. It is delivered as a record that contains two pairs of values, for example:"tag": [{"key": "some_key", "value": "some_value"}]
-
andOperator
:AND
logical operator for filters. This is an optional parameter. Use this filter to combine filtering by prefix, size, or object tag in a single rule. With theandOperator
logical operator, you can set up filtering by multiple tags at the same time. To do this, specify the tags in thetag
key as an array of objects each containing two pairs of values.Example of a filter with the
AND
logical operator:"filter": { "andOperator": { "prefix": "backup/", "tag": [ { "key": "key_1", "value": "value_1" }, { "key": "key_2", "value": "value_2" } ], "objectSizeGreaterThan": "16", "objectSizeLessThan": "1024" } }
If no object filter is set, the rule applies to all objects in the bucket.
-
-
Transitions
: Parameter of a rule for changing the storage class of any objects from standard (STANDARD
) to cold (COLD
orSTANDARD_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. Format: ISO 8601 , e.g.,YYYY-MM-DDT00:00:00Z
. Time: Always 00:00 UTC. You cannot use thedate
key together with thedays
key. This is an optional parameter.days
: Number of days from object creation date after which the rule will take effect. The minimum value is1
. You cannot use thedays
key together with thedate
key. 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 transferred as an array, e.g.:
"transitions": [{ "days": "<number_of_days>", "storage_class": "<storage_class>" }]
-
expiration
: Parameter of a rule for deleting any objects. This is an optional parameter. It may contain:date
: Date after which you want the rule to take effect. Format: ISO 8601 , e.g.,YYYY-MM-DDT00:00:00Z
. Time: Always 00:00 UTC. You cannot use thedate
key together with thedays
key. This is an optional parameter.days
: Number of days from object creation date after which the rule will take effect. The minimum value is1
. You cannot use thedays
key together with thedate
key. This is an optional parameter.expired_object_delete_marker
: Deletes the delete marker for which expired object versions no longer exist. It may take either thetrue
orfalse
value. This is an optional parameter.
-
noncurrent_transitions
: Parameter of a rule for changing the storage class of non-current object versions from standard (STANDARD
) to cold (COLD
orSTANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. It may contain:noncurrent_days
: Number of days before the 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 completed 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
: Rule starts to apply after the number of days from the classification of the delete marker version as non-current, which is specified in this parameter, expires. 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 completed, save the configuration to a file, e.g.,
lifecycles.json
. -
-
View a 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******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Using the
NAME
column, save the name of the bucket to set up the lifecycles in. -
Run the following command:
yc storage bucket update \ --name <bucket_name> \ --lifecycle-rules-from-file <configuration_file_path>
Where:
--name
: Name of the bucket to set up the 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 via the AWS CLI:
-
Define the object lifecycle configuration in JSON format. For 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 be 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 whose size is greater than or equal to the set one. This is an optional parameter. -
ObjectSizeLessThan
: Maximum object size in bytes. The rule applies to objects whose size is less than or equal to the set one. This is an optional parameter. -
Tag
: Object's tag. This is an optional parameter. The rule applies to objects to which the specified tag is assigned. It is delivered as a record that contains two pairs of values, for example:"Tag": [{"Key": "some_key", "Value": "some_value"}]
-
And
: AND logical operator for filters. This is an optional parameter. Use this filter to combine filtering by prefix, size, or object tag in a single rule. With theAnd
logical operator, you can set up filtering by multiple tags at the same time. To do this, specify the tags in theTags
key as an array of objects each containing two pairs of values.Example of a filter with the
AND
logical operator:"Filter": { "And": { "Prefix": "backup/", "Tags": [ { "Key": "key_1", "Value": "value_1" }, { "Key": "key_2", "Value": "value_2" } ], "ObjectSizeGreaterThan": 1, "ObjectSizeLessThan": 1024 } }
If no object filter is set, the rule applies to all objects in the bucket.
-
-
Status
: Rule status. This is a required parameter. Values:Enabled
: Rule enabled.Disabled
: Rule disabled.
-
Transitions
: Parameter of a rule for changing the storage class of any objects from standard (STANDARD
) to cold (COLD
orSTANDARD_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, Format: ISO 8601 , e.g.,YYYY-MM-DD
. Time: Always 00:00 UTC. You cannot use theDate
key together with theDays
key. This is an optional parameter.Days
: Number of days from object creation date after which the storage class will be changed. The minimum value is1
. You cannot use theDays
key together with theDate
key. 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 transferred as an array:
"Transitions": [{ "Days": "<number_of_days>", "StorageClass": "<storage_class>" }]
To specify the
Transitions
parameter, you must specify thePrefix
parameter in the configuration file. At the same time, thePrefix
value must 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, Format: ISO 8601 , e.g.,YYYY-MM-DD
. Time: Always 00:00 UTC. You cannot use theDate
key together with theDays
key. This is an optional parameter.Days
: Number of days from object creation date after which the object will be deleted. The minimum value is1
. You cannot use theDays
key together with theDate
key. This is an optional parameter.ExpiredObjectDeleteMarker
: Deletes the delete marker for which expired object versions no longer exist. It may take either thetrue
orfalse
value. This is an optional parameter.
-
NoncurrentVersionTransitions
: Parameter of a rule for changing the storage class of non-current object versions from standard (STANDARD
) to cold (COLD
orSTANDARD_IA
) or ice (ICE
) or from cold to ice. This is an optional parameter. It may contain:NoncurrentDays
: Number of days before changing the storage class of non-current object versions. 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 specify the
NoncurrentVersionTransitions
parameter, you must specify thePrefix
parameter in the configuration file. At the same time, thePrefix
value must 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 that indicates the number of days before deleting non-current object versions. The minimum value is1
. -
AbortIncompleteMultipartUpload
: Parameter of a rule for removing all parts of multipart uploads that were not completed within the specified number of days. This is an optional parameter.The rule has the required
DaysAfterInitiation
parameter that indicates the number of days since the upload start. The minimum value is1
.
Make sure to specify at least one of the following parameters:
Transitions
,Expiration
,NoncurrentVersionTransition
,NoncurrentVersionExpiration
, orAbortIncompleteMultipartUpload
.Once completed, save the configuration to a file, e.g.,
lifecycles.json
. -
-
Upload the configuration to a 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 static key and a key ID used to authenticate in Object Storage.
-
In the configuration file, describe 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
: ID of the static access key.secret_key
: Value of the secret access key.
lifecycle_rule
parameters:-
id
: Unique rule ID, which must be 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 to which the rule applies. This is an optional parameter. -
object_size_greater_than
: Minimum object size in bytes. The rule applies to objects whose size is greater than or equal to the set one. This is an optional parameter. -
object_size_less_than
: Maximum object size in bytes. The rule applies to objects whose size is less than or equal to the set one. This is an optional parameter. -
tag
: Object tag. This is an optional parameter. The rule applies to objects to which the specified tag is assigned. It is delivered as a record that contains two pairs of values, for example:tag { key = "some_key" value = "some_value" }
-
And
:AND
logical operator for filters. This is an optional parameter. Use this filter to combine filtering by prefix, size, or object tag in a single rule. With theAnd
logical operator, you can set up filtering by multiple tags at the same time. To do this, specify the tags askey = value
pairs in thetags
block.filter { and { prefix = "backup/" tags = { key1 = "value1" key2 = "value2" } object_size_greater_than = 1 object_size_less_than = 1024 } }
If no object filter is set, the rule applies to all objects in the bucket.
-
-
enabled
: Rule status. This is a required parameter. -
abort_incomplete_multipart_upload_days
: Parameter of a rule for removing all parts of multipart uploads that were not completed within the specified number of days. This is an optional parameter. -
expiration
: Parameter of a rule for deleting any objects. This is an optional parameter. -
transition
: Parameter of a rule for changing the storage class of any objects from standard (STANDARD
) to cold (COLD
orSTANDARD_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 standard (STANDARD
) to cold (COLD
orSTANDARD_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 use thedate
parameter together with thedays
parameter. This is an optional parameter.days
: Number of days from object creation date after which the rule will take effect. The minimum value is1
. You cannot use thedays
parameter together with thedate
parameter. This is an optional parameter.expired_object_delete_marker
: Deletes the delete marker for which expired object versions no longer exist. It may take either thetrue
orfalse
value. This is an optional parameter.
transition
parameters:date
: Date after which you want the rule to take effect. You cannot use thedate
parameter together with thedays
parameter. This is an optional parameter.days
: Number of days from object creation date after which the rule will take effect. The minimum value is 1. You cannot use thedays
parameter together with thedate
parameter. 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 is 1. This is a required parameter.
noncurrent_version_transition
parameters:days
: Number of days before the transition. The minimum value is 1. 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 resources you can create with Terraform, see the provider documentation
. -
Make sure the configuration files are correct.
-
In the command line, go to the folder where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply
-
Confirm that you want to create the resources.
All the resources you need will then be created in the specified folder. You can check the new resources and their configuration 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 a lifecycle configuration in the XML format.