Python 如何使用boto设置S3对象生命周期?

Python 如何使用boto设置S3对象生命周期?,python,amazon-s3,boto,Python,Amazon S3,Boto,我已经上传了几个文件到亚马逊S3使用。但是,我未能使用语句设置生命周期(我知道这可以使用来完成,但我需要允许每个用户决定要保留文件多长时间) 该解决方案正确地记录了文档,但我无法对此进行配置。有人能纠正我的代码吗 谢谢 key='key' secretkey='secretkey' #build the connection conn = S3Connection(key, secretkey) bucket = conn.create_bucket('przm') k=Key(bucket)

我已经上传了几个文件到亚马逊S3使用。但是,我未能使用语句设置生命周期(我知道这可以使用来完成,但我需要允许每个用户决定要保留文件多长时间)

该解决方案正确地记录了文档,但我无法对此进行配置。有人能纠正我的代码吗

谢谢

key='key'
secretkey='secretkey'

#build the connection
conn = S3Connection(key, secretkey)
bucket = conn.create_bucket('przm')
k=Key(bucket)

#select and upload the file
name1='run1'
k.key=name1
k.set_contents_from_filename('RUN')
link1='https://s3.amazonaws.com/przm/'+name1
#allow anyone can download this file
k.set_acl('public-read-write')

#delete this file after one day. Can anyone give me some help here?
configure_lifecycle(lifecycle_config, headers=None)
在本例中,您没有显示“lifecycle_config”的来源。但是,您应该创建一个生命周期对象,如下所示:

import boto.s3.lifecycle
lifecycle_config = boto.s3.lifecycle.Lifecycle()
lifecycle_config.add_rule('lc_rule_1', '/', 'Enabled', 1)
bucket.configure_lifecycle(lifecycle_config)
有关生命周期对象以及上述参数的含义的详细信息,请参见类

拥有生命周期对象后,可以在调用中使用该对象,如下所示:

import boto.s3.lifecycle
lifecycle_config = boto.s3.lifecycle.Lifecycle()
lifecycle_config.add_rule('lc_rule_1', '/', 'Enabled', 1)
bucket.configure_lifecycle(lifecycle_config)