我尝试使用以下代码列出一个特定 S3 存储桶中的对象:
conn = client('s3') # again assumes boto.cfg setup, assume AWS S3
for key in conn.list_objects(Bucket='arn:aws:s3:::my-bucket1/NAME/OF/FOLDER/')['Contents']:
print(key['Key'])
但出现此错误:
Invalid bucket name "arn:aws:s3:::my-bucket1/NAME/OF/FOLDER/": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:(s3|s3-object-lambda):[a-z\-0-9]*:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-.]{1,63}$|^arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$"
我还尝试了其他一些方法(指定 S3 存储桶的路径),但没有任何效果。我能做什么?
应该是
Bucket='my-bucket1'
for key in conn.list_objects(Bucket='my-bucket1', Prefix='NAME/OF/FOLDER/')['Contents']:
print(key['Key'])
只需将存储桶名称指定为“my-bucket1”,前后不要添加任何内容