mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
🚀 feat: Add support for custom AWS endpoint in S3 initialization (#6431)
This commit is contained in:
parent
a7e7813a09
commit
692fba51d8
2 changed files with 13 additions and 2 deletions
|
|
@ -480,6 +480,7 @@ FIREBASE_APP_ID=
|
||||||
# S3 AWS Bucket #
|
# S3 AWS Bucket #
|
||||||
#========================#
|
#========================#
|
||||||
|
|
||||||
|
AWS_ENDPOINT_URL=
|
||||||
AWS_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
AWS_REGION=
|
AWS_REGION=
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ let s3 = null;
|
||||||
* If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are provided, they will be used.
|
* If AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are provided, they will be used.
|
||||||
* Otherwise, the AWS SDK's default credentials chain (including IRSA) is used.
|
* Otherwise, the AWS SDK's default credentials chain (including IRSA) is used.
|
||||||
*
|
*
|
||||||
|
* If AWS_ENDPOINT_URL is provided, it will be used as the endpoint.
|
||||||
|
*
|
||||||
* @returns {S3Client|null} An instance of S3Client if the region is provided; otherwise, null.
|
* @returns {S3Client|null} An instance of S3Client if the region is provided; otherwise, null.
|
||||||
*/
|
*/
|
||||||
const initializeS3 = () => {
|
const initializeS3 = () => {
|
||||||
|
|
@ -22,18 +24,26 @@ const initializeS3 = () => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read the custom endpoint if provided.
|
||||||
|
const endpoint = process.env.AWS_ENDPOINT_URL;
|
||||||
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
||||||
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
region,
|
||||||
|
// Conditionally add the endpoint if it is provided
|
||||||
|
...(endpoint ? { endpoint } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
if (accessKeyId && secretAccessKey) {
|
if (accessKeyId && secretAccessKey) {
|
||||||
s3 = new S3Client({
|
s3 = new S3Client({
|
||||||
region,
|
...config,
|
||||||
credentials: { accessKeyId, secretAccessKey },
|
credentials: { accessKeyId, secretAccessKey },
|
||||||
});
|
});
|
||||||
logger.info('[initializeS3] S3 initialized with provided credentials.');
|
logger.info('[initializeS3] S3 initialized with provided credentials.');
|
||||||
} else {
|
} else {
|
||||||
// When using IRSA, credentials are automatically provided via the IAM Role attached to the ServiceAccount.
|
// When using IRSA, credentials are automatically provided via the IAM Role attached to the ServiceAccount.
|
||||||
s3 = new S3Client({ region });
|
s3 = new S3Client(config);
|
||||||
logger.info('[initializeS3] S3 initialized using default credentials (IRSA).');
|
logger.info('[initializeS3] S3 initialized using default credentials (IRSA).');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue