How do I pass grants with boto3's upload_file?
<p>I have a command using the AWS CLI</p>

<pre><code>aws s3 cp y:/mydatafolder s3://&lt;bucket&gt;/folder/subfolder --recursive --grants read=uri=http://policyurl 
</code></pre>

<p>The first part is easy to do in python, I can use <code>os.walk</code> to walk the folders and get the files and upload the file using the <code>boto3.s3client.upload_file</code> command.  The second part I'm struggling with is the <code>--grants read</code> part.  </p>

<p>What boto3 function do I need to call to do this?</p>

<p>Thanks</p>

<p>In your <code>upload_file</code> call you will need to pass <code>GrantRead</code> in <code>ExtraArgs</code>. Generally speaking you can pass in any arguments that <a href="http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.put_object" rel="nofollow"><code>put_object</code></a> would take this way. For example:</p>

<pre><code>import boto3

s3 = boto3.client('s3')
file_path = '/foo/bar/baz.txt'
s3.upload_file(
    Filename=file_path,
    Bucket='&lt;bucket&gt;',
    Key='key',
    ExtraArgs={
        'GrantRead': 'uri="http://policyurl"'
    }
)
</code></pre>

python python-2.7 boto3