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
+53-9Lines changed: 53 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,33 @@ When you create an object lifecycle rule, you can specify which prefix you would
31
33
5. Fill out the fields for the new rule.
32
34
6. When you are done, select **Add rule**.
33
35
36
+
### Wrangler
37
+
38
+
#### Set up Wrangler
39
+
40
+
To begin, install [`npm`](https://docs.npmjs.com/getting-started). Then [install Wrangler, the Developer Platform CLI](/workers/wrangler/install-and-update/).
41
+
42
+
#### Add a lifecycle rule
43
+
44
+
Log in to Wrangler with the [`wrangler login` command](/workers/wrangler/commands/#login). Then add a lifecycle rule to your bucket by running the [`r2 bucket lifecycle add` command](/workers/wrangler/commands/#lifecycle-add).
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).
59
+
34
60
### S3 API
35
61
36
-
Below is an example of configuring a lifecycle policy with different sets of rules for different potential use cases.
62
+
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
63
38
64
```js title="Configure the S3 client to interact with R2"
39
65
constclient=newS3({
@@ -47,7 +73,7 @@ const client = new S3({
47
73
});
48
74
```
49
75
50
-
```javascript title="Configure the lifecycle policy for a bucket"
76
+
```javascript title="Set the lifecycle configuration for a bucket"
51
77
await client
52
78
.putBucketLifecycleConfiguration({
53
79
Bucket:"testBucket",
@@ -116,7 +142,17 @@ await client
116
142
.promise();
117
143
```
118
144
119
-
## Get a bucket's lifecycle policy
145
+
## Get lifecycle rules for your bucket
146
+
147
+
### Wrangler
148
+
149
+
To get the list of lifecycle rules associated with your bucket, run the [`r2 bucket lifecycle list` command](/workers/wrangler/commands/#lifecycle-list).
150
+
151
+
```sh
152
+
npx wrangler r2 bucket lifecycle list <BUCKET_NAME>
153
+
```
154
+
155
+
### S3 API
120
156
121
157
```js
122
158
importS3from"aws-sdk/clients/s3.js";
@@ -132,7 +168,7 @@ const client = new S3({
132
168
region:"auto",
133
169
});
134
170
135
-
// Get lifecycle policy for bucket
171
+
// Get lifecycle configuration for bucket
136
172
console.log(
137
173
await client
138
174
.getBucketLifecycleConfiguration({
@@ -142,7 +178,7 @@ console.log(
142
178
);
143
179
```
144
180
145
-
## Delete a bucket's lifecycle policy
181
+
## Delete lifecycle rules from your bucket
146
182
147
183
### Dashboard
148
184
@@ -152,6 +188,14 @@ console.log(
152
188
4. Under **Object lifecycle rules**, select the rules you would like to delete.
153
189
5. When you are done, select **Delete rule(s)**.
154
190
191
+
### Wrangler
192
+
193
+
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).
1076
+
1077
+
### `lifecycle remove`
1078
+
1079
+
Remove an [object lifecycle](/r2/buckets/object-lifecycles/) rule from an R2 bucket.
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
1091
+
1092
+
### `lifecycle list`
1093
+
1094
+
List [object lifecycle](/r2/buckets/object-lifecycles/) rules for an R2 bucket.
1095
+
1096
+
```txt
1097
+
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).
1104
+
1105
+
### `lifecycle set`
1106
+
1107
+
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).
1119
+
1050
1120
### `sippy enable`
1051
1121
1052
1122
Enable [Sippy](/r2/data-migration/sippy/) incremental migration for a bucket.
0 commit comments