Skip to main content

Handle Amazon S3 PUT/DELETE/sign interactions

Project description

Objects / files can be put in S3 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.

Available as Python package at http://pypi.python.org/pypi/pyawsbuckets [ pip install pyawsbuckets ] Source at https://github.com/mhenwood/pyawsbuckets

Usage

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”)

Delete an object from S3:

aws_interface.delete('bucket999', 'somefile.pdf')

Get a signed URL which gives access to a private object, but only for (e.g.) 15 minutes:

expiring_url = aws_interface.sign_object_request('https', 'bucket999', 'somefile.pdf', 15)

Using HTTPS

You can specify ‘https’ as the protocol for putting 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.

Known Limitations

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyawsbuckets-1.1.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyawsbuckets-1.1.0-py2.7.egg (8.7 kB view details)

Uploaded Egg

File details

Details for the file pyawsbuckets-1.1.0.tar.gz.

File metadata

  • Download URL: pyawsbuckets-1.1.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyawsbuckets-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0bff7d538febefdfb46fad32d35f08cf5c80cf5214159e7f78c847272de718fb
MD5 928805b2b406a9397c9a897e56499f0f
BLAKE2b-256 759ee593d72115110cf8bdc50037eebf74e41b5848720fa95d755ac371d86f36

See more details on using hashes here.

File details

Details for the file pyawsbuckets-1.1.0-py2.7.egg.

File metadata

File hashes

Hashes for pyawsbuckets-1.1.0-py2.7.egg
Algorithm Hash digest
SHA256 db1facc9b30938d0a7a305bc458f69865a56d437b33d5d4c3e0e364d64ed688e
MD5 8c781aae59efcdc664bd75537e3065a8
BLAKE2b-256 7356439b8cedac57de794c1c8ff7ee564c648110d3d30e09bba43fbf6d2f6f23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page