Home > Back-end >  How to get filenames list from S3 bucket using Boto3
How to get filenames list from S3 bucket using Boto3

Time:10-31

How to get a list of all the filenames present in the s3 bucket.

import boto3
import pandas as pd
s3 = boto3.client('s3')
s3 = boto3.resource( service_name='s3', region_name='us',
aws_access_key_id='pjh', aws_secret_access_key='mm')

ob = []
for i in s3.Bucket('xyzbucket').objects.all():
    ob.append(i)

test= []
for i in ob:
    test.append(i['Contents']['key'])

TypeError: 's3.ObjectSummary' object is not subscriptable

CodePudding user response:

It should be:

test.append(i.key)

not

test.append(i['Contents']['key'])
  • Related