title: How to download the latest file of an S3 bucket using Boto3?
body: <p>The other questions I could find were refering to an older version of Boto. I would like to download the latest file of an S3 bucket. In the <a href="http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.list_object_versions" rel="noreferrer">documentation</a> I found that there is a method list_object_versions() that gets you a boolean IsLatest. Unfortunately I only managed to set up a connection and to download a file. Could you please show me how I can extend my code to get the latest file of the bucket? Thank you</p>
  
  <pre><code>import boto3
  conn = boto3.client('s3',
                      region_name="eu-west-1",
                      endpoint_url="customendpoint",
                      config=Config(signature_version="s3", s3={'addressing_style': 'path'}))
  </code></pre>
  
  <p>From here I dont know how to get the latest added file from a bucket called <code>mytestbucket</code>. There are various csv files in the bucket but all of course with a different name.</p>
  
  <p>Update:</p>
  
  <pre><code>import boto3
  from botocore.client import Config
  
  s3 = boto3.resource('s3', region_name="eu-west-1", endpoint_url="custom endpoint", aws_access_key_id = '1234', aws_secret_access_key = '1234', config=Config(signature_version="s3", s3={'addressing_style': 'path'}))
  my_bucket = s3.Bucket('mytestbucket22')
  unsorted = []
  for file in my_bucket.objects.filter():
     unsorted.append(file)
  
  files = [obj.key for obj in sorted(unsorted, key=get_last_modified, reverse=True)][0:9]
  </code></pre>
  
  <p>This gives me the following error:</p>
  
  <pre><code>NameError: name 'get_last_modified' is not defined
  </code></pre>