Handle Amazon S3 PUT/GET/DELETE/sign interactions
Handle Amazon S3 interactions
Objects / files can be put into S3, retrieved from and deleted from S3. Also signed URLs can be generated to allow limited-time access to a particular object in an S3 bucket.
Requires Python 2.7 or above.
Initiate the access object with your credentials:
from pyawsbuckets import AwsInterface aws_interface = AwsInterface(amazon_access_key, amazon_secret_key)
Put an object into an existing bucket at S3 (repeat: the bucket must ALREADY exist):
aws_interface.put( 'https', 'bucket999', 'somefile.pdf', content)
Put an object into an existing bucket at S3, activating server-side encryption for that object:
aws_interface.put( 'https', 'bucket999', 'somefile.pdf', content, server_side_encryption=True)
The put method also accepts an optional content_type keyword argument which should be a standard internet media type (e.g. “image/jpeg”)
Retrieve a given object from a given bucket:
object_contents = aws_interface( 'https', 'bucket999', 'somefile.pdf')
Delete an object from S3:
Expiring access URL
Get a signed URL which gives access to a private object, but only for (e.g.) 15 minutes. This is useful if you wish for users to be able to download private objects directly, but only for a brief window of time (to stop, for example, link sharing):
expiring_url = aws_interface.sign_object_request('https', 'bucket999', 'somefile.pdf', 15)
You can specify ‘https’ as the protocol for putting/getting files and for signing.
However you should bear in mind that given the way wildcard certificates work, the certificate presented by the S3 service will not match the requested hostname if your bucket name contains dots (periods).
This is because a certificate for “*.s3.amazon.com” will work nicely for hostnames like “foo.s3.amazon.com” and “foo-example-com.s3.example.com” but will NOT work for hostnames like “foo.bar.s3.amazon.com”. This is a feature of wildcard certificates and their jurisdiction, not of S3 or this library.
Because the bucket name gets translated into a hostname, this matters. It matters because your request will fail.
In short: avoid dots (periods) in bucket names if you plan to use https at all.
Does not currently handle ‘307’ redirects from AWS - You will receive these for the first few hours of a bucket’s lifetime, until AWS’s DNS changes have propagated fully.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|pyawsbuckets-1.2.0-py2.7.egg (9.2 kB) Copy SHA256 Checksum SHA256||2.7||Egg||May 29, 2013|
|pyawsbuckets-1.2.0.tar.gz (5.1 kB) Copy SHA256 Checksum SHA256||–||Source||May 29, 2013|