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

后端 未结 2 1201
时光说笑
时光说笑 2021-02-15 10:06

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:17

    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)
    

提交回复
热议问题