Skip to content
Start here

Get Object Lifecycle Rules

client.R2.Buckets.Lifecycle.Get(ctx, bucketName, params) (*BucketLifecycleGetResponse, error)
GET/accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle

Get object lifecycle rules for a bucket.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
bucketName string

Name of the bucket.

maxLength64
minLength3
params BucketLifecycleGetParams
AccountID param.Field[string]

Path param: Account ID.

maxLength32
Jurisdiction param.Field[BucketLifecycleGetParamsCfR2Jurisdiction]Optional

Header param: Jurisdiction where objects in this bucket are guaranteed to be stored.

const BucketLifecycleGetParamsCfR2JurisdictionDefault BucketLifecycleGetParamsCfR2Jurisdiction = "default"
const BucketLifecycleGetParamsCfR2JurisdictionEu BucketLifecycleGetParamsCfR2Jurisdiction = "eu"
const BucketLifecycleGetParamsCfR2JurisdictionFedramp BucketLifecycleGetParamsCfR2Jurisdiction = "fedramp"
ReturnsExpand Collapse
type BucketLifecycleGetResponse struct{…}
Rules []BucketLifecycleGetResponseRuleOptional
ID string

Unique identifier for this rule.

Conditions BucketLifecycleGetResponseRulesConditions

Conditions that apply to all transitions of this rule.

Prefix string

Transitions will only apply to objects/uploads in the bucket that start with the given prefix, an empty prefix can be provided to scope rule to all objects/uploads.

Enabled bool

Whether or not this rule is in effect.

AbortMultipartUploadsTransition BucketLifecycleGetResponseRulesAbortMultipartUploadsTransitionOptional

Transition to abort ongoing multipart uploads.

Condition BucketLifecycleGetResponseRulesAbortMultipartUploadsTransitionConditionOptional

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

MaxAge int64
Type BucketLifecycleGetResponseRulesAbortMultipartUploadsTransitionConditionType
DeleteObjectsTransition BucketLifecycleGetResponseRulesDeleteObjectsTransitionOptional

Transition to delete objects.

Condition BucketLifecycleGetResponseRulesDeleteObjectsTransitionConditionOptional

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

One of the following:
type BucketLifecycleGetResponseRulesDeleteObjectsTransitionConditionR2LifecycleAgeCondition struct{…}

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

MaxAge int64
Type BucketLifecycleGetResponseRulesDeleteObjectsTransitionConditionR2LifecycleAgeConditionType
type BucketLifecycleGetResponseRulesDeleteObjectsTransitionConditionR2LifecycleDateCondition struct{…}

Condition for lifecycle transitions to apply on a specific date.

Date Time
formatdate-time
Type BucketLifecycleGetResponseRulesDeleteObjectsTransitionConditionR2LifecycleDateConditionType
StorageClassTransitions []BucketLifecycleGetResponseRulesStorageClassTransitionOptional

Transitions to change the storage class of objects.

Condition BucketLifecycleGetResponseRulesStorageClassTransitionsCondition

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

One of the following:
type BucketLifecycleGetResponseRulesStorageClassTransitionsConditionR2LifecycleAgeCondition struct{…}

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

MaxAge int64
Type BucketLifecycleGetResponseRulesStorageClassTransitionsConditionR2LifecycleAgeConditionType
type BucketLifecycleGetResponseRulesStorageClassTransitionsConditionR2LifecycleDateCondition struct{…}

Condition for lifecycle transitions to apply on a specific date.

Date Time
formatdate-time
Type BucketLifecycleGetResponseRulesStorageClassTransitionsConditionR2LifecycleDateConditionType
StorageClass BucketLifecycleGetResponseRulesStorageClassTransitionsStorageClass

Get Object Lifecycle Rules

package main

import (
  "context"
  "fmt"

  "github.com/stainless-sdks/cloudflare-go"
  "github.com/stainless-sdks/cloudflare-go/option"
  "github.com/stainless-sdks/cloudflare-go/r2"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  lifecycle, err := client.R2.Buckets.Lifecycle.Get(
    context.TODO(),
    "example-bucket",
    r2.BucketLifecycleGetParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", lifecycle.Rules)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "rules": [
      {
        "id": "Expire all objects older than 24 hours",
        "conditions": {
          "prefix": "prefix"
        },
        "enabled": true,
        "abortMultipartUploadsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "deleteObjectsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "storageClassTransitions": [
          {
            "condition": {
              "maxAge": 0,
              "type": "Age"
            },
            "storageClass": "InfrequentAccess"
          }
        ]
      }
    ]
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "rules": [
      {
        "id": "Expire all objects older than 24 hours",
        "conditions": {
          "prefix": "prefix"
        },
        "enabled": true,
        "abortMultipartUploadsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "deleteObjectsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "storageClassTransitions": [
          {
            "condition": {
              "maxAge": 0,
              "type": "Age"
            },
            "storageClass": "InfrequentAccess"
          }
        ]
      }
    ]
  },
  "success": true
}