Project

General

Profile

rgw-lifecycle-repro.py

Ben Hines, 04/12/2017 05:07 AM

Download (941 Bytes)

 
1
#!/usr/bin/python
2
import boto3
3
import botocore
4
access_key = '<accesskey>'
5
secret_key = '<secretkey>'
6
bucket = '<bucketname>'
7
hostname = '<rgwurl>'
8
endpoint_url = 'http://{}:{}'.format(hostname, 80)
9
config = botocore.client.Config(s3={'addressing_style':'path','signature_version':'s3'})
10

    
11
session = boto3.session.Session(aws_access_key_id=access_key, aws_secret_access_key=secret_key)
12
client = session.client('s3', endpoint_url=endpoint_url, config=config)
13
s3 = session.resource('s3', endpoint_url=endpoint_url, config=config)
14

    
15
bucket_lifecycle = s3.BucketLifecycle(bucket)
16
print(bucket_lifecycle)
17

    
18
response = client.put_bucket_lifecycle_configuration(
19
    Bucket=bucket,
20
    LifecycleConfiguration={
21
        'Rules': [
22
            {
23
#'Prefix': '',
24
                'Expiration': {
25
                    'Days':1,
26
                },
27
                'ID': '0',
28
                'Status': 'Enabled',
29
            },
30
        ]
31
    }
32
)
33
print response