How can I get only one level of objects in a S3 bucket?

后端 未结 2 1794
孤街浪徒
孤街浪徒 2021-02-15 09:39

I want to list only the objects in a bucket that aren\'t buckets themselves. Is there a way of doing this short of parsing out the results of ListBucket?

2条回答
  •  悲&欢浪女
    2021-02-15 10:12

    There is a better approach using the latest boto3 version (1.14 as of now) and list_objects_v2 method.

    import boto3
    
    s3_client = boto3.client('s3')
    response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix=your_prefix)
    
    print(response)
    

提交回复
热议问题