Smart_open: How can I define ACL for boto3?

Created on 25 Feb 2019  路  3Comments  路  Source: RaRe-Technologies/smart_open

I need to define an ACL in my current setting when I write on S3, otherwise the file will end up with no permissions (nobody can read it). How can I do that with smart_open?

Most helpful comment

This works:

with smart_open.open(
s3_path, 'w', transport_params={'session': session,  'multipart_upload_kwargs': {'ACL': 'bucket-owner-full-control'}}) as out_file:
     out_file.write(...)

All 3 comments

Please note that I cannot pass it as a kwarg, as the following line will fail:

            session = kwargs.pop(
                's3_session',
                boto3.Session(profile_name=kwargs.pop('profile_name', None))
            )
>           s3 = session.resource('s3', **kwargs)
E           TypeError: resource() got an unexpected keyword argument 'ACL'

One hacky solution here is to call the s3 implementation directly:

smart_open.smart_open_s3.open(s3_bucket, s3_key, 'wb', **{
    's3_session': boto_session,
    'ACL': 'bucket-owner-full-control',
})

This works:

with smart_open.open(
s3_path, 'w', transport_params={'session': session,  'multipart_upload_kwargs': {'ACL': 'bucket-owner-full-control'}}) as out_file:
     out_file.write(...)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

eschwartz picture eschwartz  路  5Comments

menshikh-iv picture menshikh-iv  路  5Comments

rileypeterson picture rileypeterson  路  4Comments

dmcguire81 picture dmcguire81  路  5Comments

perrygeo picture perrygeo  路  6Comments