title: Using boto to delete all buckets
body: <p>I've been tasked with creating a script to delete all the current S3 buckets and create some new ones. This is something that they want to do on an ongoing basis. So far I have all the preliminaries:</p>
  
  <pre><code>import boto
  from boto.s3.key import Key
  import boto.s3.connection
  from __future__ import print_function
  
  conn = boto.s3.connect_to_region('us-east-1',
                                   aws_access_key_id='my_access_key', aws_secret_access_key='my_secret_key')
  
  ls = conn.get_all_buckets()
  
  print(*ls,sep='\n')
  </code></pre>
  
  <p>This gives me a list of all the current buckets. Now if I want to remove the buckets my understanding is that they have to be emptied first, using a method something like:</p>
  
  <pre><code>db = conn.get_bucket('bucket_name')
  for key in db.list():
    key.delete()
  </code></pre>
  
  <p>And then I could do:</p>
  
  <pre><code>conn.delete_bucket('bucket_name')
  </code></pre>
  
  <p>I want to set it up such that it pulls each bucket name from 'ls', but I'm not sure how to go about this. I tried this:</p>
  
  <pre><code>for i in ls:
      db = conn.get_bucket('i')
      for key in db.list():
          key.delete()
  </code></pre>
  
  <p>But I get an error "S3ResponseError: 400 Bad Request". I'm getting a sneaking suspicion that it's not pulling the separate elements from the list. Do I maybe have to get data frames involved? As far as I know, boto doesn't have an option to just nuke all the folders outright.</p>