3. awss3tools

Files create, update, read, delete through AWS S3.

class awss3tools.AwsS3Tools(bucket, aws_access_key_id, aws_secret_access_key, open_file=None, validate=False)[source]

Bases: boto.s3.connection.S3Connection

AwsS3Tools

Parameters:
  • bucket (str) – s3 bucket Name
  • aws_access_key_id (str) – aws_access_key_id
  • aws_secret_access_key (str) – aws_secret_access_key
  • open_file (str) – filename, the same with s3 object key name.
  • validate (bool) – validate bucket is exist or not. Default is False for not to call get_all_keys.

See also

validate in get_bucket in boto.s3.connection.S3Connection

Return type:boto.s3.connection.S3Connection
Returns:boto.s3.connection.S3Connection

Connect bucket with filename:

>>> FILES = AwsS3Tools('toomore-aet', AWSID, AWSKEY, 'toomore.txt')
>>> print FILES

Connect bucket without filename but using open():

>>> FILES = AwsS3Tools('toomore-aet', AWSID, AWSKEY)
>>> FILES.open('toomore.txt')
delete()[source]

Delete file.

open(filename)[source]

Open a file by keyname

Parameters:filename (str) – filename, the same with s3 object key name.
>>> FILES.open('toomore.txt')

Note

No return value, key object will put into self.keys

read()[source]

Read file from S3

Return type:cStringIO.StringIO()
>>> content = FILES.read()
>>> print content.read()
save(file_data, make_public=False)[source]

Save file to S3

Parameters:
  • file_data (file) – file data
  • make_public (bool) – to be public
Return type:

int

Returns:

file size in byte.

>>> with open('./README.md') as file_data:
...     print FILES.save(file_data, True)
update(file_data, *args, **kwargs)[source]

Update file.

Parameters:file_data (file) – file data
Return type:int
Returns:file size in byte.
>>> content = FILES.read()
>>> print content.read()
>>> content.writelines('Toomore is Toomore')
>>> FILES.update(content)
>>> print FILES.read().getvalue()

Todo

update key with the same acl.

Previous topic

2. awssestools

Next topic

4. awssqstools

This Page