Managing Lifecycles

This page describes how to enable Object Lifecycle Management and gives examples of lifecycle policies. For a description of this feature, including the actions and conditions it supports, see Object Lifecycle Management.

Setting up lifecycle management

Enabling Lifecycle Management

To enable lifecycle management for a bucket:

Console

  1. Open the Cloud Storage browser in the Google Cloud Platform Console.
    Open the Cloud Storage browser

  2. In the bucket list, find the bucket you want to enable, and click None in the Lifecycle column.

    The lifecycle rules page appears.

  3. Click Add rule.

  4. In the page that appears, specify a configuration.

    1. Select the condition(s) under which an action is taken.

    2. Click Continue.

    3. Select the action to take when an object meets the condition(s).

    4. Click Continue.

    5. Click Save.

gsutil

  1. Create a .json file with the lifecycle configuration rules you would like to apply (see examples below).

  2. Use the lifecycle set command to apply the configuration, replacing [VALUES_IN_BRACKETS] with the appropriate values:

    gsutil lifecycle set [LIFECYCLE_CONFIG_FILE] gs://[BUCKET_NAME]

REST APIs

JSON API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Create a .json file with the lifecycle configuration rules you would like to apply (see examples below).
  3. Use cURL to call the JSON API with a PATCH Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X PATCH --data-binary @[LIFECYCLE_CONFIG_FILE].json \
      -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      -H "Content-Type: application/json" \
      "https://www.googleapis.com/storage/v1/b/[BUCKET_NAME]?fields=lifecycle"

XML API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Create a request body that contains the lifecycle configuration rules you would like to apply (see examples below).
  3. Use cURL to call the XML API with a PUT Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X PUT --data-binary @[XML_FILE].xml \
      -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      "https://[BUCKET_NAME].storage.googleapis.com/?lifecycle"

Disabling Lifecycle Management

To disable lifecycle management for a bucket:

Console

  1. Open the Cloud Storage browser in the Google Cloud Platform Console.
    Open the Cloud Storage browser

  2. In the bucket list, find the bucket you want to disable, and click Enabled in the Lifecycle column.

    The lifecycle rules page appears.

  3. Click Delete all.

  4. In the confirmation window that appears, click Delete.

gsutil

  1. Create a .json file with an empty lifecycle configuration:

    {}

  2. Use the lifecycle set command, replacing [VALUES_IN_BRACKETS] with the appropriate values:

    gsutil lifecycle set [LIFECYCLE_CONFIG_FILE] gs://[BUCKET_NAME]

REST APIs

JSON API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Create a .json file with an empty lifecycle configuration:
    {}
  3. Use cURL to call the JSON API with a PATCH Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X PATCH --data-binary @[LIFECYCLE_CONFIG_FILE].json \
      -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      -H "Content-Type: application/json" \
      "https://www.googleapis.com/storage/v1/b/[BUCKET_NAME]?fields=lifecycle"

XML API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Create a request body that contains an empty lifecycle configuration:
    <?xml version="1.0" encoding="UTF-8" ?>
    <LifecycleConfiguration/>
  3. Use cURL to call the XML API with a PUT Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X PUT --data-binary @[XML_FILE].xml \
      -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      "https://[BUCKET_NAME].storage.googleapis.com/?lifecycle"

Checking Lifecycle Configuration

To check the lifecycle configuration set on a bucket:

Console

  1. Open the Cloud Storage browser in the Google Cloud Platform Console.
    Open the Cloud Storage browser

  2. In the bucket list, the lifecycle status of each bucket is found in the Lifecycle column.

    You can click on this status to add, view, edit, and delete rules.

gsutil

  1. Use the lifecycle get command, replacing [VALUES_IN_BRACKETS] with the appropriate values::

    gsutil lifecycle get gs://[BUCKET_NAME]

REST APIs

JSON API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. .
  2. Use cURL to call the JSON API with a GET Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X GET -H "Authorization: Bearer [OAUTH2_TOKEN]" \
      "https://www.googleapis.com/storage/v1/b/[BUCKET_NAME]?fields=lifecycle"

XML API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Use cURL to call the XML API with a GET Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X GET \
        -H "Authorization: Bearer [OAUTH2_TOKEN]" \
        "https://[BUCKET_NAME].storage.googleapis.com/?lifecycle"

Lifecycle configuration examples

The following examples show specific lifecycle configurations that accomplish deleting objects and changing the storage class of objects when common criteria are met. For a detailed discussion of lifecycle configurations, including a list of available actions and conditions, see Object Lifecycle Management.

Delete an object

The following lifecycle configuration defines two rules. The first rule deletes any live objects older than 30 days. The second rule deletes archived objects older than 10 days. Note that the second rule requires object versioning to be enabled in order for its criteria to ever be met.

Console

The following rule deletes live objects older than 30 days:

Delete live objects older than 30 days.

The following rule deletes archived objects older than 10 days:

Delete archived objects with 3+ newer versions.

gsutil

The following lifecycle configuration can be applied to a bucket by enabling lifecycle management.

{
"lifecycle": {
  "rule": [
  {
    "action": {"type": "Delete"},
    "condition": {
      "age": 30,
      "isLive": true
    }
  },
  {
    "action": {"type": "Delete"},
    "condition": {
      "age": 10,
      "isLive": false
    }
  }
]
}
}

For the generalized format of a lifecycle configuration file, see the bucket resource representation for JSON.

REST APIs

JSON API

The following lifecycle configuration can be applied to a bucket by enabling lifecycle management.

{
"lifecycle": {
  "rule": [
  {
    "action": {"type": "Delete"},
    "condition": {
      "age": 30,
      "isLive": true
    }
  },
  {
    "action": {"type": "Delete"},
    "condition": {
      "age": 10,
      "isLive": false
    }
  }
]
}
}

For the generalized format of a lifecycle configuration file, see the bucket resource representation for JSON.

XML API

The following lifecycle configuration can be applied to a bucket by enabling lifecycle management.

<?xml version="1.0" encoding="UTF-8" ?>
<LifecycleConfiguration>
    <Rule>
        <Action>
            <Delete/>
        </Action>
        <Condition>
            <IsLive>true</IsLive>
            <Age>30</Age>
        </Condition>
    </Rule>
    <Rule>
        <Action>
            <Delete/>
        </Action>
        <Condition>
            <IsLive>false</IsLive>
            <Age>10</Age>
        </Condition>
    </Rule>
</LifecycleConfiguration>

For the generalized format of a lifecycle configuration file, see the lifecycle configuration format for XML.

Change an object's storage class

The following lifecycle configuration defines two rules to change the storage class of objects in a bucket. The first rule changes Multi-Regional Storage, Standard Storage, and Durable Reduced Availability Storage objects older than 365 days (one year) to Nearline Storage. The second rule changes Nearline Storage objects older than 1095 days (three years) to Coldline Storage. This lifecycle configuration applies to objects in the bucket regardless of when they were added.

Note that this lifecycle configuration applies to buckets in multi-regional locations. For buckets in regional locations, replace "MULTI_REGIONAL" with "REGIONAL".

Console

The following rule moves objects to Nearline after 365 days:

Set objects to Nearline after 365 days.

The following rule moves objects to Coldline after 1095 days:

Set objects to Coldline after 1095 days.

gsutil

The following lifecycle configuration can be applied to a bucket by enabling lifecycle management.

{
"lifecycle": {
  "rule": [
  {
    "action": {
      "type": "SetStorageClass",
      "storageClass": "NEARLINE"
    },
    "condition": {
      "age": 365,
      "matchesStorageClass": ["MULTI_REGIONAL", "STANDARD", "DURABLE_REDUCED_AVAILABILITY"]
    }
  },
  {
    "action": {
      "type": "SetStorageClass",
      "storageClass": "COLDLINE"
    },
    "condition": {
      "age": 1095,
      "matchesStorageClass": ["NEARLINE"]
    }
  }
]
}
}

For the generalized format of a lifecycle configuration file, see the bucket resource representation for JSON.

REST APIs

JSON API

The following lifecycle configuration can be applied to a bucket by enabling lifecycle management.

{
"lifecycle": {
  "rule": [
  {
    "action": {
      "type": "SetStorageClass",
      "storageClass": "NEARLINE"
    },
    "condition": {
      "age": 365,
      "matchesStorageClass": ["MULTI_REGIONAL", "STANDARD", "DURABLE_REDUCED_AVAILABILITY"]
    }
  },
  {
    "action": {
      "type": "SetStorageClass",
      "storageClass": "COLDLINE"
    },
    "condition": {
      "age": 1095,
      "matchesStorageClass": ["NEARLINE"]
    }
  }
]
}
}

For the generalized format of a lifecycle configuration file, see the bucket resource representation for JSON.

XML API

The following lifecycle configuration can be applied to a bucket by enabling lifecycle management.

<?xml version="1.0" encoding="UTF-8" ?>
<LifecycleConfiguration>
    <Rule>
        <Action>
            <SetStorageClass>NEARLINE</SetStorageClass>
        </Action>
        <Condition>
            <Age>365</Age>
            <MatchesStorageClass>MULTI_REGIONAL</MatchesStorageClass>
            <MatchesStorageClass>STANDARD</MatchesStorageClass>
            <MatchesStorageClass>DURABLE_REDUCED_AVAILABILITY</MatchesStorageClass>
        </Condition>
    </Rule>
    <Rule>
        <Action>
            <SetStorageClass>COLDLINE</SetStorageClass>
        </Action>
        <Condition>
            <Age>1095</Age>
            <MatchesStorageClass>NEARLINE</MatchesStorageClass>
        </Condition>
    </Rule>
</LifecycleConfiguration>

For the generalized format of a lifecycle configuration file, see the lifecycle configuration format for XML.

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Storage Documentation