將多個檔案設為公開
市議會非常重視公開透明。他們希望居民也能自行分析 Get It Done 的請求,以及其被列為優先處理的方式。
他們請 Sam 將自 2019 年初以來的所有 Get It Done 彙整報告也一併公開。
Sam 已經初始化 boto3 的 S3 用戶端,並指派給變數 s3。
在這個練習中,你將協助 Sam 開放資料:把 gid-staging bucket 中每個物件的 ACL 設為 public-read,讓全世界都能存取!
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 列出
'gid-staging'bucket 中以'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['____']))