Python boto, list contents of specific dir in bucket

前端 未结 7 1798
难免孤独
难免孤独 2020-12-13 18:19

I have S3 access only to a specific directory in an S3 bucket.

For example, with the s3cmd command if I try to list the whole bucket:

             


        
7条回答
  •  隐瞒了意图╮
    2020-12-13 18:51

    This can be done using:

    s3_client = boto3.client('s3')
    objects = s3_client.list_objects_v2(Bucket='bucket_name')
    for obj in objects['Contents']:
      print(obj['Key'])
    

提交回复
热议问题