From 61f329d8df318c9f1a17189a61512355e4c72477 Mon Sep 17 00:00:00 2001 From: Ehsan Aliakbar Date: Thu, 15 Dec 2022 01:28:41 +0330 Subject: [PATCH] Support custom S3 endpoint --- .gitignore | 1 + README.md | 2 ++ exporter.js | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index de52ea0..2059219 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,5 @@ another-service/2020/12/01/01.log.gz another-service/2020/12/01/23.log.gz another-service/2020/12/02/00.log.gz ``` + +You can Also set `S3_ENDPOINT` env for using an S3-Compatible Object Storage like Minio diff --git a/exporter.js b/exporter.js index 2e2d2d3..57e18cb 100644 --- a/exporter.js +++ b/exporter.js @@ -16,11 +16,18 @@ module.exports = function createExporter (opts) { assert(awsSecretAccessKey, `The parameter 'opts.awsSecretAccessKey' is required.`) assert(lokiHost, `The parameter 'opts.lokiHost' is required.`) - const s3 = new S3({ + s3_config = { region: awsRegion, accessKeyId: awsAccessKeyId, secretAccessKey: awsSecretAccessKey - }) + } + + if (process.env.S3_ENDPOINT) { + s3_config.endpoint = process.env.S3_ENDPOINT + s3_config.s3ForcePathStyle = true + } + + const s3 = new S3(s3_config) const createS3WriteStream = (key) => new s3WriteStream(s3, {Bucket: awsBucket, Key: key})