Skip to main content

Synapse S3 Storage Provider

This module can be used by synapse as a storage provider, allowing it to fetch and store media in Amazon S3.

Usage

The s3_storage_provider.py should be on the PYTHONPATH when starting synapse.

Example of entry in synapse config:

media_storage_providers:
- module: s3_storage_provider.S3StorageProviderBackend
  store_local: True
  store_remote: True
  store_synchronous: True
  config:
    bucket: <S3_BUCKET_NAME>
    # All of the below options are optional, for use with non-AWS S3-like
    # services, or to specify access tokens here instead of some external method.
    region_name: <S3_REGION_NAME>
    endpoint_url: <S3_LIKE_SERVICE_ENDPOINT_URL>
    access_key_id: <S3_ACCESS_KEY_ID>
    secret_access_key: <S3_SECRET_ACCESS_KEY>
    session_token: <S3_SESSION_TOKEN>

    # Server Side Encryption for Customer-provided keys
    #sse_customer_key: <S3_SSEC_KEY>
    # Your SSE-C algorithm is very likely AES256
    # Default is AES256.
    #sse_customer_algo: <S3_SSEC_ALGO>

    # The object storage class used when uploading files to the bucket.
    # Default is STANDARD.
    #storage_class: "STANDARD_IA"

    # Prefix for all media in bucket, can't be changed once media has been uploaded
    # Useful if sharing the bucket between Synapses
    # Blank if not provided
    #prefix: "prefix/to/files/in/bucket"

    # The maximum number of concurrent threads which will be used to connect
    # to S3. Each thread manages a single connection. Default is 40.
    #
    #threadpool_size: 20

    # Set request_checksum_calculation or response_checksum_validation. 
    # Depending on your S3 provider you may need to set these values,
    # especially if you are using a self-hosted system that does not
    # support the functionality provided by AWS.
    # Default is 'when_required'
    # request_checksum_calculation: "when_supported" | "when_required"
    # response_checksum_validation: "when_supported" | "when_required"
    

This module uses boto3, and so the credentials should be specified as described here.

Regular cleanup job

There is additionally a script at scripts/s3_media_upload which can be used in a regular job to upload content to s3, then delete that from local disk. This script can be used in combination with configuration for the storage provider to pull media from s3, but upload it asynchronously.

Once the package is installed, the script should be run somewhat like the following. We suggest using tmux or screen as these can take a long time on larger servers.

database.yaml should contain the keys that would be passed to psycopg2 to connect to your database. They can be found in the contents of the database.args parameter in your homeserver.yaml.

More options are available in the command help.

> cd s3_media_upload
# cache.db will be created if absent. database.yaml is required to
# contain PG credentials
> ls
cache.db database.yaml
# Update cache from /path/to/media/store looking for files not used
# within 2 months
> s3_media_upload update /path/to/media/store 2m
Syncing files that haven't been accessed since: 2018-10-18 11:06:21.520602
Synced 0 new rows
100%|█████████████████████████████████████████████████████████████| 1074/1074 [00:33<00:00, 25.97files/s]
Updated 0 as deleted

> s3_media_upload upload /path/to/media/store matrix_s3_bucket_name --storage-class STANDARD_IA --delete
# prepare to wait a long time

Packaging and release

For maintainers:

  1. Update the __version__ in setup.py. Then commit and push the changes:

    git add setup.py
    git commit -m "vX.Y.Z"
    git push
    
  2. Create a signed tag and push that:

    git tag -s vX.Y.Z
    git push origin vX.Y.Z
    
  3. Create a release on GitHub for this version.

  4. When published, a GitHub action workflow will build the package and upload to PyPI.

Metadata

Release files for synapse-s3-storage-provider 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for synapse-s3-storage-provider 1.7.0
File Size Uploaded Provenance
synapse_s3_storage_provider-1.7.0.tar.gz 18.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for synapse-s3-storage-provider 1.7.0
File Interpreter ABI Platform
synapse_s3_storage_provider-1.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.6 kB

Release files / synapse_s3_storage_provider-1.7.0.tar.gz

Download URL synapse_s3_storage_provider-1.7.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b4f3322febf7b85672b1da0438c4e4b487273152539d640dbdb9dd862e8ad648
BLAKE2b-256 checksum
How to use checksums
9d7dbfdd6dcf7f119f757ea7b30bcb3f4dcd985214b2e9fac11895c7f5f7af98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / synapse_s3_storage_provider-1.7.0-py3-none-any.whl

Download URL synapse_s3_storage_provider-1.7.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38d17e0d20da58bdcedbabf733f41de4fb47c1724eadcfbb8deab6f76fd7a9c9
BLAKE2b-256 checksum
How to use checksums
5edf6075c19c6680b481039bb5538750a2e97aaab9dfb6a8da0bf7cfaa067e8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for synapse-s3-storage-provider 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page