title: Uploading a file to a S3 bucket with a prefix using Boto3
body: <p>I am attempting to upload a file into a S3 bucket, but I don't have access to the root level of the bucket and I need to upload it to a certain prefix instead. The following code:</p>
  
  <pre><code>import boto3
  s3 = boto3.resource('s3')
  open('/tmp/hello.txt', 'w+').write('Hello, world!')
  s3_client.upload_file('/tmp/hello.txt', bucket_name, prefix+'hello-remote.txt')
  </code></pre>
  
  <p>Gives me an error:</p>
  
  <p><code>An error occurred (AccessDenied) when calling the PutObject operation: Access Denied: ClientError Traceback (most recent call last): File "/var/task/tracker.py", line 1009, in testHandler s3_client.upload_file('/tmp/hello.txt', bucket_name, prefix+'hello-remote.txt') File "/var/runtime/boto3/s3/inject.py", line 71, in upload_file extra_args=ExtraArgs, callback=Callback) File "/var/runtime/boto3/s3/transfer.py", line 641, in upload_file self._put_object(filename, bucket, key, callback, extra_args) File "/var/runtime/boto3/s3/transfer.py", line 651, in _put_object **extra_args) File "/var/runtime/botocore/client.py", line 228, in _api_call return self._make_api_call(operation_name, kwargs) File "/var/runtime/botocore/client.py", line 492, in _make_api_call raise ClientError(parsed_response, operation_name) ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
  </code></p>
  
  <p><code>bucket_name</code> is in the format <code>abcd</code> while <code>prefix</code> is in the format <code>a/b/c/d/</code>. I'm not sure if the error is due to the slashes being wrong or if there's some way you can specify the prefix elsewhere, or if I don't have write permissions (although I supposedly do).</p>
  
  <p>This code executes without any errors:</p>
  
  <pre><code>for object in output_bucket.objects.filter(Prefix=prefix):
      print(object.key)
  </code></pre>
  
  <p>Although there is no output as the bucket is empty. </p>