Quick way to list all files in Amazon S3 bucket?

前端 未结 28 1812
星月不相逢
星月不相逢 2020-11-28 01:32

I have an amazon s3 bucket that has tens of thousands of filenames in it. What\'s the easiest way to get a text file that lists all the filenames in the bucket?

28条回答
  •  余生分开走
    2020-11-28 02:03

    There are couple of ways you can go about it. Using Python

    import boto3
    
    sesssion = boto3.Session(aws_access_key_id, aws_secret_access_key)
    
    s3 = sesssion.resource('s3')
    
    bucketName = 'testbucket133'
    bucket = s3.Bucket(bucketName)
    
    for obj in bucket.objects.all():
        print(obj.key)
    

    Another way is using AWS cli for it

    aws s3 ls s3://{bucketname}
    example : aws s3 ls s3://testbucket133
    

提交回复
热议问题