A storage provider which can fetch and store media in Amazon S3.
Project description
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>
# The object storage class used when uploading files to the bucket.
# Default is STANDARD.
#storage_class: "STANDARD_IA"
# 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
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:
- Update the
__version__
in setup.py. Commit. Push. - Create a release on GitHub for this version.
- When published, a GitHub action workflow will build the package and upload to PyPI.
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
Built Distribution
File details
Details for the file synapse-s3-storage-provider-1.1.1.tar.gz
.
File metadata
- Download URL: synapse-s3-storage-provider-1.1.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b957c66861200b7aa999f2a4cd0417472ae50484f0eb81a0cc16b022748ebcb |
|
MD5 | e067a5d2478f7daea34236eaaa34ddd4 |
|
BLAKE2b-256 | 87ac320e8327c271bbd46d6c6bf1d76e97bcbb1ef0a75bdba256a6480a8196d8 |
File details
Details for the file synapse_s3_storage_provider-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: synapse_s3_storage_provider-1.1.1-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92cc682834c3888c1bd746aac542c3e29a7536f30931e3caed2be356c3866228 |
|
MD5 | 4c9a5fe26e7fe652a71bb6826d38b912 |
|
BLAKE2b-256 | 409abe5f120e18e244db818df6b729d73e0c79a6c3b6905d564b315ac59686ea |