Skip to main content

Mounting S3 Buckets

Snowcell allows you to mount your S3 buckets to your apps/code

Mountpoint is optimized for reading large files with high throughput and writing new files from a single client at a time. However it does not support appending to files.

To connect your bucket to your app, you need to provide the following:

  1. The bucket name
  2. An AWS access key
  3. An AWS secret key

To get started, import the Bucket and BucketConfig classes

from snowcell.serverless.storage import Bucket, BucketConfig
  1. Create a Bucket instance and within it setup your S3 credentials using BucketConfig

    mount_path = "./something"

    something = Bucket(
    name="something",
    mount_path=mount_path,
    config=BucketConfig(
    access_key="S3_KEY",
    secret_key="S3_SECRET",
    ),
    )
  2. Add the bucket instance to your decorator: When a request is received to start the container, Snowcell will use the secrets to mount the bucket.

    @client.function(name="my file op", cpu=1.5, memory=2, volumes=[something])
    def worker():
    # Write to the bucket.
    file_path = os.path.join(something.mount_path, "test.txt")

    try:
    with open(file_path, "w") as f:
    f.write("hello world")

    except Exception as e:
    print(e)

    # Read from the bucket.
    with open(file_path, "r") as f:
    print(f.read())

    worker()