Skip to content
Start here

Put Object Lifecycle Rules

client.R2.Buckets.Lifecycle.Update(ctx, bucketName, params) (*BucketLifecycleUpdateResponse, error)
PUT/accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle

Set the 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 BucketLifecycleUpdateParams
AccountID param.Field[string]

Path param: Account ID.

maxLength32
Rules param.Field[[]BucketLifecycleUpdateParamsRule]Optional

Body param

ID string

Unique identifier for this rule.

Conditions BucketLifecycleUpdateParamsRulesConditions

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 BucketLifecycleUpdateParamsRulesAbortMultipartUploadsTransitionOptional

Transition to abort ongoing multipart uploads.

Condition BucketLifecycleUpdateParamsRulesAbortMultipartUploadsTransitionConditionOptional

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

MaxAge int64
Type BucketLifecycleUpdateParamsRulesAbortMultipartUploadsTransitionConditionType
DeleteObjectsTransition BucketLifecycleUpdateParamsRulesDeleteObjectsTransitionOptional

Transition to delete objects.

Condition BucketLifecycleUpdateParamsRulesDeleteObjectsTransitionConditionOptional

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

One of the following:
type BucketLifecycleUpdateParamsRulesDeleteObjectsTransitionConditionR2LifecycleAgeCondition struct{…}

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

MaxAge int64
Type BucketLifecycleUpdateParamsRulesDeleteObjectsTransitionConditionR2LifecycleAgeConditionType
type BucketLifecycleUpdateParamsRulesDeleteObjectsTransitionConditionR2LifecycleDateCondition struct{…}

Condition for lifecycle transitions to apply on a specific date.

Date Time
formatdate-time
Type BucketLifecycleUpdateParamsRulesDeleteObjectsTransitionConditionR2LifecycleDateConditionType
StorageClassTransitions []BucketLifecycleUpdateParamsRulesStorageClassTransitionOptional

Transitions to change the storage class of objects.

Condition BucketLifecycleUpdateParamsRulesStorageClassTransitionsCondition

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

One of the following:
type BucketLifecycleUpdateParamsRulesStorageClassTransitionsConditionR2LifecycleAgeCondition struct{…}

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

MaxAge int64
Type BucketLifecycleUpdateParamsRulesStorageClassTransitionsConditionR2LifecycleAgeConditionType
type BucketLifecycleUpdateParamsRulesStorageClassTransitionsConditionR2LifecycleDateCondition struct{…}

Condition for lifecycle transitions to apply on a specific date.

Date Time
formatdate-time
Type BucketLifecycleUpdateParamsRulesStorageClassTransitionsConditionR2LifecycleDateConditionType
StorageClass BucketLifecycleUpdateParamsRulesStorageClassTransitionsStorageClass
Jurisdiction param.Field[BucketLifecycleUpdateParamsCfR2Jurisdiction]Optional

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

const BucketLifecycleUpdateParamsCfR2JurisdictionDefault BucketLifecycleUpdateParamsCfR2Jurisdiction = "default"
const BucketLifecycleUpdateParamsCfR2JurisdictionEu BucketLifecycleUpdateParamsCfR2Jurisdiction = "eu"
const BucketLifecycleUpdateParamsCfR2JurisdictionFedramp BucketLifecycleUpdateParamsCfR2Jurisdiction = "fedramp"
ReturnsExpand Collapse
type BucketLifecycleUpdateResponse interface{…}

Put 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.Update(
    context.TODO(),
    "example-bucket",
    r2.BucketLifecycleUpdateParams{
      AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", lifecycle)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}