Amazon S3

Creating an Amazon S3 connection allows one to store, read or delete messages in the connection’s buckets.

Creating key/value pairs in S3 buckets

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        with self.cloud.aws.s3.get('My Connection').conn.client() as client:

            # Create a key/value pair under a selected bucket
            key = 'My sample key'
            value = 'My value'
            bucket = 'skiaguuiagscauisgcqiuwxnilhqw'

            # Call S3 with the input
            client.set(key, value, bucket)

And now in AWS console:

../../../../_images/s3-sample-key.png

Accessing Boto

The underlying Python library is Boto - it is always available under a client's .impl attribute and lets one access every feature S3 supports, for instance:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        with self.cloud.aws.s3.get('My Connection').conn.client() as client:

            # List all buckets
            self.logger.info(client.impl.get_all_buckets())

            # User ID
            self.logger.info(client.impl.get_canonical_user_id())
INFO - [<Bucket: skiaguuiagscauisgcqiuwxnilhqw>]
INFO - 5699349a708b4bfa9790e8f6f5c5163cd6e3511dcf5b48c3a15814c05cf736d9