Configuring a Lifecycle Rule for a Bucket
API Description
You can use this API to configure a lifecycle rule for a bucket, to periodically transit storage classes of objects and delete objects in the bucket.
Method Definition
ObsClient.setBucketLifecycle(bucketName, lifecycle)
Request Parameters
| Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
| bucketName | str | Mandatory | Bucket name |
| lifecycle | Mandatory | Bucket lifecycle configuration |
Returned Results
| Type | Description |
|---|---|
| SDK common result object |
Sample Code
try:
from obs import Expiration, NoncurrentVersionExpiration
from obs import DateTime
from obs import Rule
from obs import Lifecycle
rule1 = Rule(id='rule1', prefix='prefix1', status='Enabled', expiration=Expiration(days=60), noncurrentVersionExpiration=NoncurrentVersionExpiration(noncurrentDays=60))
rule2 = Rule(id='rule2', prefix='prefix2', status='Enabled', expiration=Expiration(date=DateTime(2018, 12, 31)))
lifecycle = Lifecycle(rule=[rule1, rule2])
resp = obsClient.setBucketLifecycle('bucketname', lifecycle)
if resp.status < 300:
print('requestId:', resp.requestId)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc()) Last Article: Deleting a Bucket Policy
Next Article: Obtaining the Lifecycle Configuration Information of a Bucket
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.