将多个文件设为公开
市议会非常重视透明度。他们希望居民能够自行分析 Get It Done 请求以及其优先级如何确定。
他们让 Sam 将自 2019 年初以来所有 Get It Done 汇总报告也设为公开。
Sam 已经初始化 boto3 的 S3 客户端,并将其赋值给变量 s3。
在本练习中,您将帮助 Sam 通过把 gid-staging 存储桶中每个对象的 ACL 设置为 public-read 来开放这些数据,使所有人都能访问这些对象。
本练习是课程的一部分
Python 中的 AWS Boto 入门
练习说明
- 列出
'gid-staging'存储桶中以'2019/final_'开头的对象。 - 对返回结果中的每个文件,将其
ACL设为'public-read'。 - 打印每个对象的公共对象 URL。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# List only objects that start with '2019/final_'
response = s3.____(
Bucket='____', ____='____')
# Iterate over the objects
for obj in response['Contents']:
# Give each object ACL of public-read
s3.put_object_acl(____='gid-staging',
____=obj['Key'],
____='____')
# Print the Public Object URL for each object
print("https://{}.____.____.com/{}".format( '____', obj['____']))