简体   繁体   English

使用 Boto3 导航到 s3 中的子文件夹,而无需访问 ObjectList

[英]Navigate to subfolders in s3 with Boto3 without accessing the ObjectList

I am kinda stuck right now.我现在有点卡住了。

Basically i am trying to retrieve files from a s3 bucket with boto3.基本上我正在尝试使用 boto3 从 s3 存储桶中检索文件。 It all used to work, but now the administrators of the s3 bucket decided to revoke permissions for parent folders, because the bucket is shared with a lot of companies whose data we shall not access (for obvious reasons).这一切过去都有效,但现在 s3 存储桶的管理员决定撤销对父文件夹的权限,因为该存储桶与许多我们无法访问其数据的公司共享(出于显而易见的原因)。

Basically this is how we used to get to our files:基本上这就是我们过去获取文件的方式:

objects = s3_bucket.objects.filter(Prefix=s3_folder)

And then we just were going through those files as shown in the documentation:然后我们只是浏览这些文件,如文档中所示:

for obj in objects:

But now this just throws an error:但现在这只是抛出一个错误:

An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied调用 ListObjects 操作时发生错误 (AccessDenied):拒绝访问

What i am unable to figure out now is how i can connect to a s3 bucket but only retrieve the object list starting from a specific path.我现在无法弄清楚的是如何连接到 s3 存储桶,但只检索从特定路径开始的对象列表。

Let's say my files are under /all-data/reports/company-2/data/csv/year-month-day/*****.csv I know the entire path from /all-data/ to /csv/ but i need to list the contents of the csv folder (year-month-day folders).假设我的文件在 /all-data/reports/company-2/data/csv/year-month-day/*****.csv 我知道从 /all-data/ 到 /csv/ 的整个路径但是我需要列出 csv 文件夹(年-月-日文件夹)的内容。 Also i only can retrieve the object list starting from /company-2.此外,我只能检索从 /company-2 开始的对象列表。

I cannot find any function in the boto3 documentation which allows me to either directly connect to a subfolder in the bucket or otherwise let me navigate through the bucket down to /csv where i could start the list objects.我在 boto3 文档中找不到任何允许我直接连接到存储桶中的子文件夹的功能,或者让我在存储桶中导航到 /csv,在那里我可以启动列表对象。

If there is any of you who could help me out i would really appreciate it, i could not find anyone else facing the problem yet :)如果有人可以帮助我,我将不胜感激,我还找不到其他人面临这个问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM