開始使用免費開始

列出 buckets

Sam 已成功為她的 pipeline 建立好 buckets。資料工程師常會在 pipeline 中加入檢查,確認前一步驟已經成功。Sam 想加上一個檢查,確保她的 buckets 確實有被建立。

她也想練習列出 buckets。列出 buckets 能讓她用 for 迴圈對多個 bucket 進行操作。

她已經建立好 S3 的 boto3 用戶端,並指定給變數 s3

請幫 Sam 取得她 S3 帳戶中所有 buckets 的清單,並印出它們的名稱!

本練習屬於課程

Python 中的 AWS Boto 入門

檢視課程

練習說明

  • 從 S3 取得 buckets。
  • 針對 response 的 bucket 鍵進行迭代,以存取 bucket 清單。
  • 列印每個 bucket 的名稱。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Get the list_buckets response
response = s3.____()

# Iterate over Buckets from .list_buckets() response
for bucket in response['____']:
  
  	# Print the Name for each bucket
    print(bucket['____'])
編輯並執行程式碼