title: How to retrieve subfolders and files from a folder in S3 bucket using boto3?
body: <p>as I am quite new to loading from AWS S3 bucket i am facing some difficulties to query data from subfolders here is the steps and bucket description:</p>
  <blockquote>
  <p>Countries S3 bucket</p>
  <ul>
  <li>subfolder for every extraction time e.g(2021-08-12 , 2021-08-11 ,...)
  <ul>
  <li>each subfolder has the following:
  <ul>
  <li>2 sub-subfolders each contains json files that i need to query</li>
  <li>other json files also need to query</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  </blockquote>
  <p>code produced so far:</p>
  <pre><code>s3 = boto3.resource(&quot;s3&quot;)
  # Get bucket
  bucket_name = &quot;countries&quot;
  bucket = s3.Bucket(name=bucket_name)
  path = &quot;countries/&quot;
  </code></pre>
  <h4>1- This steps fetches all the outer subfolders with extraction time</h4>
  <pre><code>folders = []
  
  client = boto3.client('s3')
  result = client.list_objects(Bucket=bucket_name, Prefix=path, Delimiter='/')
  for o in result.get('CommonPrefixes'):
      folders.append(o.get('Prefix'))
  </code></pre>
  <h4>2- Next iterate for every subfolder extract all the content inside</h4>
  <pre><code>   for i in folders:
       sub = client.list_objects(Bucket = bucket_name , Prefix = folders[i] , Delimiter = '/')
  </code></pre>
  <h4>3- Next extract the jsons and subfolders , do all append or join</h4>
  <p>Currently i am failing with 2nd step as i pass <code>Prefix = folders[i]</code> while indexing by passing folders[0] returns the content of one subfolder from step 1, i am trying to iterate but get back this error <code>TypeError: list indices must be integers or slices, not str</code></p>