刪除多個桶
Get It Done 這個 app 以前叫做 Get It Made。Sam 一直覺得這名字很糟,但還是牢牢記在她腦海裡。
當她建立 pipeline 的桶時,她用了舊名的縮寫 gim-。現在她決定改用 gid-,比較能準確反映這個 app 真實(而且更好的)名稱。
她已經設定好 boto3 的 S3 用戶端,並指定給變數 s3。
請幫 Sam 刪除她帳戶中所有以 gim- 開頭的桶。接著,幫她建立一個 'gid-staging' 和一個 'gid-processed' 桶。
本練習屬於課程
Python 中的 AWS Boto 入門
練習說明
- 從 S3 取得桶的清單。
- 刪除名稱包含
'gim'的桶,並建立'gid-staging'與'gid-processed'這兩個桶。 - 列印新的桶名稱。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Get the list_buckets response
response = s3.____()
# Delete all the buckets with 'gim', create replacements.
for bucket in response['Buckets']:
if 'gim' in bucket['____']:
s3.____(Bucket=bucket['Name'])
s3.create_bucket(Bucket='____')
s3.create_bucket(Bucket='____')
# Print bucket listing after deletion
response = s3.list_buckets()
for bucket in response['____']:
print(bucket['____'])