[英]s3:listallbuckets works on aws console but not on cli
上下文:我已經配置了正確的 aws-access-key 和 aws-secret-key 我可以在 aws-console 上看到存儲桶內容,但在 aws-cli 上
這是我的 boto3 代碼
import boto3
# Enter the name of your S3 bucket here
bucket_name = 'xxxx'
# Enter the name of the region where your S3 bucket is located
region_name = 'ap-southeast-1'
# Create an S3 client
s3 = boto3.client('s3', region_name=region_name)
# List all the objects in the bucket
objects = s3.list_objects(Bucket=bucket_name)
# Print the names of all the objects in the bucket
for object in objects['Contents']:
print(object['Key'])
我的 AWS 政策下有"s3:List*"
。 我錯過了什么?
我正在嘗試使用 aws-cli 列出所有存儲桶,它可以使用 aws-console 而不是 cli。 我重新檢查了我的 aws-secret/acess 密鑰,一切正常。
編輯:aws-cli 拋出錯誤
An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
如果您的 PC 中有多個 AWS 配置文件並且您使用錯誤的配置文件調用 AWS,通常會發生這種錯誤確保默認配置文件是有權訪問 AWS 帳戶的配置文件。
如果您有多個配置文件,您還可以使用aws s3 ls --PROFILE_NAME
獲取存儲桶列表
運行aws sts get-caller identity
獲取當前調用者身份
返回請求的經過身份驗證的發件人擁有的所有存儲桶的列表。 要使用此操作,您必須具有
s3:ListAllMyBuckets
權限。
措辭有點混亂,但是:
ListBuckets
返回您的 AWS 賬戶中 S3 存儲桶的名稱列表ListObjects
返回特定 S3 存儲桶中的對象列表您的 Python 代碼正在調用list_objects()
。
AWS CLI 錯誤是ListBuckets operation: Access Denied
,這表明您正在嘗試獲取存儲桶列表,而不是對象列表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.