How to set the life cycle on a Google Cloud Bucket

Setting the life cycle on the contents of your bucket can be useful, especially for buckets containing items that are no good after a certain period of time. A Good example would be back up files for a website. Anything past 10 or 15 days would be obsolete.

  1. First thing you need to create is a json file that will hold the instructions for the lifecycle:
    nano /path/to/lifecycle_config.json


  2. Add the following instructions to the file and save:
    "lifecycle": {
      "rule": [
        "action": {"type": "Delete"},
        "condition": {
          "age": 15,
          "isLive": true

    It’s pretty self explanatory, age is for the length of time before deletion. In this example it’s set to 15 days.

  3. Now we just need to send the instructions to Google Cloud Storage.
    gsutil lifecycle set /path/to/lifecycle_config.json  gs://your-bucket/


  4. Now just double check to make sure the life cycle is set:
    gsutil lifecycle get gs://your-bucket/

    Your results should look something like your json file:

    {"rule": [{"action": {"type": "Delete"}, "condition": {"age": 15, "isLive": true}}]}

    That’s it

Leave a comment