AWS S3 download file from Flask
<p>I have created a small app that should download file from a AWS S3. </p>

<p>I can download the data correctly in this way:</p>

<pre><code> s3_client = boto3.resource('s3')
 req = s3_client.meta.client.download_file(bucket, ob_key, dest)
</code></pre>

<p>but if I add this function in a flask route it does not work anymore. I obtain this error:</p>

<p>ClientError: An error occurred (400) when calling the HeadObject operation: Bad Request</p>

<p>I'm not able to figure out why it does not work inside the route. Any idea?</p>

<p>The problem was that with flask I needed to declare s3_client as global variable instead of just inside the function. </p>

<p>Now it works perfectly!</p>

python amazon-s3 flask boto3