title: HTTP Code 400 getting objectfrom AWS S3 bucket with Boto3 in python
body: <p>I'm working on a script that is supposed to download a file from my s3 bucket and then make some changes on it. 
  The problem is that my script <strong>runs well when executed as root but does not when executed with the dedicated user</strong>.</p>
  
  <p>Here is the piece of code we are interested in :</p>
  
  <pre><code>s3 = boto3.client('s3', aws_access_key_id='xxx', aws_secret_access_key='xxx')
  
  s3.download_file('my-bucket', 'my_file.csv', '/my/path/to/file.csv')
  </code></pre>
  
  <p>When I run the script as root, no problem, the file is downloaded and the script continues, but executed with my dedicated user : </p>
  
  <p><code>logstash:x:501:501::/home/logstash:/sbin/nologin</code>, it doesn't work.</p>
  
  <p>I tried running Python interpreter as root and as logstash and executed the script command by command, it works as root but not as logstash. Here is the error :</p>
  
  <pre><code>Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python2.7/site-packages/boto3/s3/inject.py", line 126, in download_file
  extra_args=ExtraArgs, callback=Callback)
  File "/usr/local/lib/python2.7/site-packages/boto3/s3/transfer.py", line 299, in download_file
  future.result()
  File "/usr/local/lib/python2.7/site-packages/s3transfer/futures.py", line 73, in result
  return self._coordinator.result()
  File "/usr/local/lib/python2.7/site-packages/s3transfer/futures.py", line 233, in result
  raise self._exception
  botocore.exceptions.ClientError: An error occurred (400) when calling the HeadObject operation: Bad Request
  </code></pre>
  
  <p>I searched a lot on google but there is no topic about this special 'user switch' case.</p>