title: Connect to S3 accelerate endpoint with boto3
body: <p>I want to download a file into a Python file object from an S3 bucket that has acceleration activated. I came across a few resources suggesting whether to overwrite the <code>endpoint_url</code> to "s3-accelerate.amazonaws.com" and/or to use the <code>use_accelerate_endpoint</code> attribute.</p>
  
  <p>I have tried both, and several variations but the same error was returned everytime. One of the scripts I tried is:</p>
  
  <pre><code>    from botocore.config import Config
      import boto3
      from io import BytesIO
      session = boto3.session.Session()
      s3 = session.client(                                                                            
             service_name='s3',                                                                  
             aws_access_key_id=&lt;MY_KEY_ID&gt;,               
             aws_secret_access_key=&lt;MY_KEY&gt;,
             region_name="us-west-2",
         config=Config(s3={"use_accelerate_endpoint": True,
                           "addressing_style": "path"}))
     input = BytesIO() 
     s3.download_fileobj(&lt;MY_BUCKET&gt;,&lt;MY_KEY&gt;, input)
  </code></pre>
  
  <p>Returns the following error:</p>
  
  <pre><code>            ---------------------------------------------------------------------------
              ClientError                               Traceback (most recent call last)
              &lt;ipython-input-61-92b89b45f215&gt; in &lt;module&gt;()
                   11      "addressing_style": "path"}))
                   12 input = BytesIO()
              ---&gt; 13 s3.download_fileobj(bucket, filename, input)
                   14 
                   15 
  
              ~/Project/venv/lib/python3.5/site-packages/boto3/s3/inject.py in download_fileobj(self, Bucket, Key, Fileobj, ExtraArgs, Callback, Config)
                  568             bucket=Bucket, key=Key, fileobj=Fileobj,
                  569             extra_args=ExtraArgs, subscribers=subscribers)
              --&gt; 570         return future.result()
                  571 
                  572 
  
              ~/Project//venv/lib/python3.5/site-packages/s3transfer/futures.py in result(self)
                   71             # however if a KeyboardInterrupt is raised we want want to exit
                   72             # out of this and propogate the exception.
              ---&gt; 73             return self._coordinator.result()
                   74         except KeyboardInterrupt as e:
                   75             self.cancel()
  
              ~/Project/venv/lib/python3.5/site-packages/s3transfer/futures.py in result(self)
                  231         # final result.
                  232         if self._exception:
              --&gt; 233             raise self._exception
                  234         return self._result
                  235 
  
              ~/Project/venv/lib/python3.5/site-packages/s3transfer/tasks.py in _main(self, transfer_future, **kwargs)
                  253             # Call the submit method to start submitting tasks to execute the
                  254             # transfer.
              --&gt; 255             self._submit(transfer_future=transfer_future, **kwargs)
                  256         except BaseException as e:
                  257             # If there was an exception raised during the submission of task
  
              ~/Project/venv/lib/python3.5/site-packages/s3transfer/download.py in _submit(self, client, config, osutil, request_executor, io_executor, transfer_future)
                  347                 Bucket=transfer_future.meta.call_args.bucket,
                  348                 Key=transfer_future.meta.call_args.key,
              --&gt; 349                 **transfer_future.meta.call_args.extra_args
                  350             )
                  351             transfer_future.meta.provide_transfer_size(
  
              ~/Project/venv/lib/python3.5/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
                  310                     "%s() only accepts keyword arguments." % py_operation_name)
                  311             # The "self" in this scope is referring to the BaseClient.
              --&gt; 312             return self._make_api_call(operation_name, kwargs)
                  313 
                  314         _api_call.__name__ = str(py_operation_name)
  
              ~/Project/venv/lib/python3.5/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
                  603             error_code = parsed_response.get("Error", {}).get("Code")
                  604             error_class = self.exceptions.from_code(error_code)
              --&gt; 605             raise error_class(parsed_response, operation_name)
                  606         else:
                  607             return parsed_response
  
              ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
  </code></pre>
  
  <p>When I run the same script with <code>"use_accelerate_endpoint": False</code> it works fine. 
  However, it returned the same error when:</p>
  
  <ul>
  <li>I overwrite the <code>endpoint_url</code> with "s3-accelerate.amazonaws.com" </li>
  <li>I define <code>"addressing_style": "virtual"</code></li>
  </ul>
  
  <p>When running 
  <code>s3.get_bucket_accelerate_configuration(Bucket=&lt;MY_BUCKET&gt;)</code></p>
  
  <p>I get <code>{..., 'Status': 'Enabled'}</code> as expected.</p>
  
  <p>Any idea what is wrong with that code and what I should change to properly query the accelerate endpoint of that bucket?</p>
  
  <p>Using python3.5 with boto3==1.4.7, botocore==1.7.43 on Ubuntu 17.04.</p>
  
  <p>EDIT:
  I have also tried a similar script for uploads:</p>
  
  <pre><code>    from botocore.config import Config
      import boto3
      from io import BytesIO
      session = boto3.session.Session()
      s3 = session.client(                                                                            
             service_name='s3',                                                                  
             aws_access_key_id=&lt;MY_KEY_ID&gt;,               
             aws_secret_access_key=&lt;MY_KEY&gt;,
             region_name="us-west-2",
         config=Config(s3={"use_accelerate_endpoint": True,
                           "addressing_style": "virtual"}))
     output = BytesIO()
     output.seek(0)
     s3.upload_fileobj(output, &lt;MY_BUCKET&gt;,&lt;MY_KEY&gt;)
  </code></pre>
  
  <p>Which works without the <code>use_accelerate_endpoint</code> option (so my keys are fine), but returns this error when True:</p>
  
  <pre><code>   ClientError: An error occurred (SignatureDoesNotMatch) when calling the PutObject operation: The request signature we calculated does not match the signature you provided. Check your key and signing method.
  </code></pre>
  
  <p>I have tried both <code>addressing_style</code> options here as well (virtual and path)</p>