title: IOError in Boto3 download_file
body: <p><strong>Background</strong></p>
  <p>I am using the following Boto3 code to download file from S3.</p>
  <pre><code>for record in event['Records']:
      bucket = record['s3']['bucket']['name']
      key = record['s3']['object']['key']
      print (key)
      if key.find('/') &lt; 0 :
      if len(key) &gt; 4 and key[-5:].lower() == '.json': //File is uploaded outside any folder
  
          download_path = '/tmp/{}{}'.format(uuid.uuid4(), key)
      else:
          download_path = '/tmp/{}/{}'.format(uuid.uuid4(), key)//File is uploaded inside a folder
  </code></pre>
  <p>If a new file is uploaded in S3 bucket, this code is triggered and that newly uploaded file is downloaded by this code.</p>
  <p>This code works fine when uploaded outside any folder.</p>
  <p>However, when I upload a file inside a directory, IO error happens.
  Here is a dump of the IO error I am encountering.</p>
  <blockquote>
  <p>[Errno 2] No such file or directory:
  <strong>/tmp/316bbe85-fa21-463b-b965-9c12b0327f5d/test1/customer1.json.586ea9b8</strong>:
  IOError</p>
  </blockquote>
  <p><code>test1</code> is the directory inside my S3 bucket where <code>customer1.json</code> is uploaded.</p>
  <p><strong>Query</strong></p>
  <p>Any thoughts on how to resolve this error?</p>