我尝试列出存储桶中的所有文件。这是我的代码
import boto3
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('my_project')
for my_bucket_object in my_bucket.objects.all():
print(my_bucket_object.key)
Run Code Online (Sandbox Code Playgroud)
有用。我得到了所有文件的名称。但是,当我尝试对文件夹执行相同的操作时,代码会引发错误
import boto3
s3 = boto3.resource('s3')
my_bucket = s3.Bucket('my_project/data/') # add the folder name
for my_bucket_object in my_bucket.objects.all():
print(my_bucket_object.key)
Run Code Online (Sandbox Code Playgroud)
这是错误:
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid bucket name "carlos-cryptocurrency-research-project/data/": 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}$"
Run Code Online (Sandbox Code Playgroud)
我确定文件夹名称正确,并尝试将其替换为 Amazon 资源名称 (ARN) 和 S3 URI,但仍然收到错误。