s3_demo_3.py 325 B

1234567891011121314
  1. def list_files(bucket):
  2. """
  3. Function to list files in a given S3 bucket
  4. """
  5. s3 = boto3.client('s3')
  6. contents = []
  7. try:
  8. for item in s3.list_objects(Bucket=bucket)['Contents']:
  9. print(item)
  10. contents.append(item)
  11. except Exception as e:
  12. pass
  13. return contents