python - 使用 boto3 和 python 列出 s3 存储桶
问题描述
我正在使用下面的代码,并引用了许多SO答案来列出文件夹下的文件boto3
,python
但无法这样做。下面是我的代码:
s3 = boto3.client('s3')
object_listing = s3.list_objects_v2(Bucket='maxValue',
Prefix='madl-temp/')
我的 s3 路径是"s3://madl-temp/maxValue/
“ 我想在其中查找 maxValue 存储桶下是否有任何镶木地板文件,基于这些文件我必须执行以下操作:
If len(maxValue)>0:
maxValue=true
else:
maxValue=false
我正在通过Glue
作业运行它,但出现以下错误:
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjectsV2 operation: The specified bucket does not exist
解决方案
您的存储桶名称是madl-temp
,前缀是maxValue
。但在 boto3 中,情况正好相反。所以应该是:
s3 = boto3.client('s3')
object_listing = s3.list_objects_v2(Bucket='madl-temp',
Prefix='maxValue/')
要获取您必须执行的文件数:
len(object_listing['Contents']) - 1
where-1
占一个前缀maxValue/
。
推荐阅读
- python - 正则表达式在 Python 中具有负面影响
- anchor - 有什么方法可以用 JQuery 自动关闭汉堡菜单?
- ios - 由于 API 密钥无效(格式错误或缺失),操作失败
- android-recyclerview - 在回收站视图中滚动时复选框状态不断变化
- android - 每次网络更改时如何在 TextView 上更新网络类型?
- visual-studio - 如何在 Visual Studio 代码中使用键盘在文件夹之间切换?
- javascript - 如何在 WebView 的 iframe 中注入 CSS?UWP
- python - 仅从 Python 中的 MongoDB 投影中获取内部字段
- javascript - 类名作为函数中的变量,带有附加代码
- angular - Cypress - 以编程方式操作 Angular/NGRX 应用程序