You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/r2/buckets/object-lifecycles.mdx
+48-9Lines changed: 48 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,17 +5,19 @@ pcx_content_type: how-to
5
5
6
6
Object lifecycles determine the retention period of objects uploaded to your bucket and allow you to specify when objects should transition from Standard storage to Infrequent Access storage.
7
7
8
+
A lifecycle configuration is a collection of lifecycle rules that define actions to apply to objects during their lifetime.
9
+
8
10
For example, you can create an object lifecycle rule to delete objects after 90 days, or you can set a rule to transition objects to Infrequent Access storage after 30 days.
9
11
10
12
## Behavior
11
13
12
14
- Objects will typically be removed from a bucket within 24 hours of the `x-amz-expiration` value.
13
-
- When a lifecycle policy is applied that deletes objects, newly uploaded objects' `x-amz-expiration` value immediately reflects the expiration based on the new rules, but existing objects may experience a delay. Most objects will be transitioned within 24 hours but may take longer depending on the number of objects in the bucket. While objects are being migrated, you may see old applied rules from the previous policy.
15
+
- When a lifecycle configuration is applied that deletes objects, newly uploaded objects' `x-amz-expiration` value immediately reflects the expiration based on the new rules, but existing objects may experience a delay. Most objects will be transitioned within 24 hours but may take longer depending on the number of objects in the bucket. While objects are being migrated, you may see old applied rules from the previous configuration.
14
16
- An object is no longer billable once it has been deleted.
15
-
- Buckets have a default lifecycle policy to expire multipart uploads seven days after initiation.
17
+
- Buckets have a default lifecycle rule to expire multipart uploads seven days after initiation.
16
18
- When an object is transitioned from Standard storage to Infrequent Access storage, a [Class A operation](/r2/pricing/#class-a-operations) is incurred.
17
19
18
-
## Configure your bucket's object lifecycle policy
20
+
## Configure lifecycle rules for your bucket
19
21
20
22
When you create an object lifecycle rule, you can specify which prefix you would like it to apply to.
21
23
@@ -31,9 +33,28 @@ When you create an object lifecycle rule, you can specify which prefix you would
Alternatively you can set the entire lifecycle configuration for a bucket from a JSON file using the [`r2 bucket lifecycle set` command](/workers/wrangler/commands/#lifecycle-set).
The JSON file should be in the format of the request body of the [put object lifecycle configuration API](/api/operations/r2-put-bucket-lifecycle-configuration).
54
+
34
55
### S3 API
35
56
36
-
Below is an example of configuring a lifecycle policy with different sets of rules for different potential use cases.
57
+
Below is an example of configuring a lifecycle configuration (a collection of lifecycle rules) with different sets of rules for different potential use cases.
37
58
38
59
```js title="Configure the S3 client to interact with R2"
39
60
constclient=newS3({
@@ -47,7 +68,7 @@ const client = new S3({
47
68
});
48
69
```
49
70
50
-
```javascript title="Configure the lifecycle policy for a bucket"
71
+
```javascript title="Set the lifecycle configuration for a bucket"
51
72
await client
52
73
.putBucketLifecycleConfiguration({
53
74
Bucket:"testBucket",
@@ -116,7 +137,17 @@ await client
116
137
.promise();
117
138
```
118
139
119
-
## Get a bucket's lifecycle policy
140
+
## Get lifecycle rules for your bucket
141
+
142
+
### Wrangler
143
+
144
+
To get the list of lifecycle rules associated with your bucket, run the [`r2 bucket lifecycle list` command](/workers/wrangler/commands/#lifecycle-list).
145
+
146
+
```sh
147
+
npx wrangler r2 bucket lifecycle list <BUCKET_NAME>
148
+
```
149
+
150
+
### S3 API
120
151
121
152
```js
122
153
importS3from"aws-sdk/clients/s3.js";
@@ -132,7 +163,7 @@ const client = new S3({
132
163
region:"auto",
133
164
});
134
165
135
-
// Get lifecycle policy for bucket
166
+
// Get lifecycle configuration for bucket
136
167
console.log(
137
168
await client
138
169
.getBucketLifecycleConfiguration({
@@ -142,7 +173,7 @@ console.log(
142
173
);
143
174
```
144
175
145
-
## Delete a bucket's lifecycle policy
176
+
## Delete lifecycle rules from your bucket
146
177
147
178
### Dashboard
148
179
@@ -152,6 +183,14 @@ console.log(
152
183
4. Under **Object lifecycle rules**, select the rules you would like to delete.
153
184
5. When you are done, select **Delete rule(s)**.
154
185
186
+
### Wrangler
187
+
188
+
To remove a specific lifecycle rule from your bucket, run the [`r2 bucket lifecycle remove` command](/workers/wrangler/commands/#lifecycle-remove).
- Sets the lifecycle rule action to transition objects to Infrequent Access storage after this number of days. Note you can provide only one of `--ia-transition-days` or `--ia-transition-date`.
- Sets the lifecycle rule action to transition objects to Infrequent Access storage after this date (YYYY-MM-DD). Note you can provide only one of `--ia-transition-days` or `--ia-transition-date`.
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
1149
+
1150
+
### `lifecycle list`
1151
+
1152
+
List [object lifecycle](/r2/buckets/object-lifecycles/) rules for an R2 bucket.
1153
+
1154
+
```txt
1155
+
wrangler r2 bucket lifecycle list <NAME> [OPTIONS]
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
1162
+
1163
+
### `lifecycle set`
1164
+
1165
+
Set the [object lifecycle](/r2/buckets/object-lifecycles/) configuration for an R2 bucket from a JSON file.
- Path to the JSON file containing lifecycle configuration (file must be in format of request body of [put object lifecycle configuration API](/api/operations/r2-put-bucket-lifecycle-configuration)).
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
1177
+
1106
1178
### `sippy enable`
1107
1179
1108
1180
Enable [Sippy](/r2/data-migration/sippy/) incremental migration for a bucket.
0 commit comments