Python boto, list contents of specific dir in bucket

前端 未结 7 1807
难免孤独
难免孤独 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

    For boto3

    import boto3
    
    s3 = boto3.resource('s3')
    my_bucket = s3.Bucket('my_bucket_name')
    
    for object_summary in my_bucket.objects.filter(Prefix="dir_name/"):
        print(object_summary.key)
    

提交回复
热议问题