gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 02:48:57 26 4
gpt4 key购买 nike

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

boto API reference for S3正确记录configure_lifecycle(lifecycle_config, headers=None)作为解决方案,但我无法配置它。任何人都可以更正我的代码吗?

谢谢!

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”的来源。但是,您应该做的是创建一个 Lifecycle 对象,如下所示:

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

参见类 boto.s3.lifecycle有关 Lifecycle 对象的详细信息以及上述参数的含义。

一旦你有了生命周期对象,你就可以在调用 configure_lifecycle() 时使用它,像这样:

bucket.configure_lifecycle(lifecycle_config)

关于python - 如何使用 boto 设置 S3 对象生命周期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10555608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com