Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Object Storage
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Buckets
      • Creating a bucket
      • Deleting a bucket
      • Limiting the maximum size of a bucket
      • Allowing public access to a bucket
      • Bucket encryption
      • Managing object lifecycles
      • Managing CORS configurations
      • Managing bucket policies
      • Managing bucket versioning
      • Editing a bucket ACL
      • Enabling logging
    • Objects
      • Uploading an object
      • Getting information about an object
      • Downloading an object
      • Getting a public link to an object
      • Deleting an object
      • Deleting all objects
      • Deleting a partially uploaded object
      • Editing an object ACL
    • Static website hosting
      • Hosting setup
      • Support for your own domain
      • Support for multiple domain names
      • Configuring HTTPS
    • Access management
      • Applying an access policy
  • Practical guidelines
    • Getting object query statistics with S3 Select
    • Getting website traffic statistics with S3 Select
    • Generating a billing report with resource break-down using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment
    • Analyzing logs in DataLens
  • Concepts
    • Overview
    • Bucket
    • Objects
    • Bucket versioning
    • Object lifecycles
    • CORS
    • Static website hosting
    • Pre-signed URLs
    • Multipart upload
    • Access control lists (ACLs)
    • Bucket Policy
    • Uploading files via an HTML form
    • Storage class
    • Logging actions with a bucket
    • Backups
    • TLS protocol
    • S3 Select query language
    • Quotas and limits
  • Tools
    • All tools
    • Console clients
      • AWS CLI
      • S3cmd
    • File browsers
      • CyberDuck
      • WinSCP
    • SDK
      • AWS SDK for Java
      • Python SDK (boto)
      • The AWS SDK for .NET
      • AWS SDK for C++
      • AWS SDK for PHP
      • AWS SDK for Go
    • FUSE
      • GeeseFS
      • s3fs
      • goofys
    • FTP
      • Docker container for (S)FTP(S)
  • API reference
    • REST (Amazon S3-compatible)
      • How to use the API
      • Signing requests
      • API reference
        • All services and methods
        • Bucket
          • All methods
          • create
          • getBucketEncryption
          • getMeta
          • listObjects
          • listBuckets
          • deleteBucket
          • deleteBucketEncryption
          • putBucketEncryption
          • putBucketVersioning
          • getBucketVersioning
          • putBucketLogging
          • getBucketLogging
          • listObjectVersions
        • Object
          • All methods
          • upload
          • get
          • copy
          • getObjectMeta
          • delete
          • deleteMultipleObjects
          • options
          • selectObjectContent
        • Multipart upload
          • General multipart upload procedure
          • startUpload
          • uploadPart
          • copyPart
          • listParts
          • abortUpload
          • completeUpload
          • listUploads
        • Static Website Hosting
          • All methods
          • upload
          • get
          • delete
          • Static website response codes
        • CORS
          • All methods
          • XML structure of CORS configuration
          • upload
          • get
          • delete
        • Lifecycles
          • All methods
          • XML structure of lifecycle configuration
          • upload
          • get
          • delete
        • ACL
          • All methods
          • XML structure of ACL configuration
          • objectGetAcl
          • objectPutAcl
          • bucketGetAcl
          • bucketPutAcl
        • Bucket Policy
          • All methods
          • GetBucketPolicy
          • PutBucketPolicy
          • DeleteBucketPolicy
          • Data schema
          • Actions
          • Conditions
        • Common request headers
        • Common response headers
        • Responses
    • gRPC and REST
      • Authentication in the API
      • gRPC
        • Overview
        • BucketService
        • OperationService
      • REST
        • Overview
        • Bucket
          • Overview
          • create
          • delete
          • deleteHTTPSConfig
          • get
          • getHTTPSConfig
          • getStats
          • list
          • setHTTPSConfig
          • update
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
  • Questions and answers
  1. Step-by-step instructions
  2. Buckets
  3. Managing object lifecycles

Managing lifecycles of object in buckets

Written by
Yandex Cloud

    Object Storage lets you manage lifecycles of objects in a bucket.

    Management console
    AWS CLI
    Terraform
    1. In the management console, go to the bucket you want to configure object lifecycles for.

    2. Select Lifecycle.

    3. Click Configure.

    4. On the page that opens, you can add, remove, and edit configuration rules.

      To create a rule:

      1. Enable the Status option. With this option, you can enable or disable a rule without deleting it from a configuration.
      2. Complete the fields below:
        • Description: Freeform description of the rule.
        • Prefix: Characters taken from the beginning of the object key of the required length. The prefix is used to match objects to a rule. If a rule must apply to all objects, select All objects.
      3. Select an object type and the action to apply to objects when the rule is triggered.
        • Expiration: Remove all objects from bucket.
        • Transition: Transfer all objects to cold storage.
        • NoncurrentVersionExpiration: Remove non-current object versions from bucket.
        • NoncurrentVersionTransition: Transfer non-current object versions to cold storage.
        • AbortIncompleteMultipartUpload: Remove of all parts of failed multipart uploads from bucket.
      4. Select the rule trigger. Depending on type, you can select:
        • Number of days: Rule triggers after a specified number of days.
        • Exact date: On specified date.
        • Deletion marker without noncurrent versions: After an object has only one current version. Valid only for the Expiration type.
      5. Select a rule trigger time:
        • Trigger time: Number of days after an object is uploaded that a rule must trigger.
        • Trigger date: Date when a rule must trigger.
      6. 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.

    Note

    In the management console, you can't use a single rule to set the criteria for deleting objects or changing the object storage class. Use a separate rule for each type of criteria.

    To upload a configuration via the AWS CLI:

    1. Define the object lifecycle configuration in JSON format. For example:

      {
        "Rules": [
          {
            "ID": "DeleteOldBackups",
            "Filter": {
              "Prefix": "backup/"
            },
            "Status": "Enabled",
            "Expiration": {
              "Days": 180
            }
          }
        ]
      }
      

      When you're done, you can save your configuration as a file, like lifecycles.json.

    2. Upload the configuration to a bucket, like backup-bucket:

      aws s3api put-bucket-lifecycle-configuration \
        --bucket backup-bucket \
        --endpoint-url=https://storage.yandexcloud.net \
        --lifecycle-configuration file://lifecycles.json
      

    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.

    1. In the configuration file, describe the parameters of resources that you want to create:

      • access_key: The ID of the static access key.
      • secret_key: The value of the secret access key.
      • bucket: Bucket name. Required parameter.

      lifecycle_rule parameters:

      • id: Unique rule ID. Must be no more than 255 characters. Optional.
      • prefix: Object key prefix that identifies one or more objects that the rule applies to. Optional.
      • enabled: Rule status. Required parameter.
      • abort_incomplete_multipart_upload_days: The number of days after the start of a multipart upload when it should be completed. Optional.
      • expiration: Object expiration date for deleting non-current object versions. Optional.
      • transition: Object expiration date for changing the storage class. Optional.
      • noncurrent_version_expiration: Rule for deleting non-current object versions. Optional.
      • noncurrent_version_transition: Rule for changing the storage class of non-current object versions. Optional.

      Make sure to specify at least one of the following parameters: abort_incomplete_multipart_upload_days, expiration, transition, noncurrent_version_expiration, or noncurrent_version_transition.

      expiration parameters:

      • date: Date after which you want the rule to take effect. Optional.
      • days: The number of days after creating an object when the rule takes effect. Optional.

      transition parameters:

      • date: Date after which you want the rule to take effect. Optional.
      • days: The number of days after creating an object when the rule takes effect. Optional.
      • storage_class: Storage class to move the object to. Either COLD or STANDARD_IA. Required parameter.

      noncurrent_version_expiration parameters:

      • days: The number of days before expiration. Required parameter.

      noncurrent_version_transition parameters:

      • days: The number of days before the transition. Required parameter.
      • storage_class: Storage class to move the object to. Either COLD or STANDARD_IA. Required parameter.
      provider "yandex" {
        cloud_id  = "<cloud ID>"
        folder_id = "<folder ID>"
        zone      = "<availability zone>"
        token     = "<OAuth token>"
        }
      
      resource "yandex_storage_bucket" "bucket" {
        bucket     = "<bucket name>"
        acl        = "private"
        access_key = "<key ID>"
        secret_key = "<secret key>"
      
        lifecycle_rule {
          id      = "log"
          enabled = true
          prefix = "log/"
      
          transition {
            days          = 30
            storage_class = "COLD"
          }
      
          expiration {
            days = 90
          }
        }
      
        lifecycle_rule {
          id      = "tmp"
          prefix  = "tmp/"
          enabled = true
      
          expiration {
            date = "2020-12-21"
          }
        }
      }
      
      resource "yandex_storage_bucket" "versioning_bucket" {
        bucket     = "<bucket name>"
        acl        = "private"
        access_key = "<key ID>"
        secret_key = "<secret key>"
      
        versioning {
          enabled = true
        }
      
        lifecycle_rule {
          prefix  = "config/"
          enabled = true
      
          noncurrent_version_transition {
            days          = 30
            storage_class = "COLD"
          }
      
          noncurrent_version_expiration {
            days = 90
          }
        }
      }
      

      For more information about the resources you can create using Terraform, see the provider documentation.

    2. Make sure that the configuration files are correct.

      1. In the command line, go to the directory where you created the configuration file.

      2. Run the check using the command:

        terraform plan
        

      If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

    3. Deploy the cloud resources.

      1. If the configuration doesn't contain any errors, run the command:

        terraform apply
        
      2. Confirm that you want to create the resources.

      Afterwards, all the necessary resources are created in the specified folder. You can check that the resources are there with the correct settings using the management console.

    Was the article helpful?

    Language / Region
    © 2022 Yandex.Cloud LLC