Feature: Support role-based authentication for AWS (#2470)

* Storage, DynamoDBChatMemory - Make AWS credentials optional to support role-based authentication

* Lint fix
This commit is contained in:
Daniel D'Abate
2024-05-30 00:40:01 +02:00
committed by GitHub
parent 48ac815f8e
commit 912c8f3d5b
2 changed files with 28 additions and 9 deletions
+18 -5
View File
@@ -1,6 +1,13 @@
import path from 'path'
import fs from 'fs'
import { DeleteObjectsCommand, GetObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client } from '@aws-sdk/client-s3'
import {
DeleteObjectsCommand,
GetObjectCommand,
ListObjectsV2Command,
PutObjectCommand,
S3Client,
S3ClientConfig
} from '@aws-sdk/client-s3'
import { Readable } from 'node:stream'
import { getUserHome } from './utils'
@@ -311,14 +318,20 @@ export const getS3Config = () => {
const secretAccessKey = process.env.S3_STORAGE_SECRET_ACCESS_KEY
const region = process.env.S3_STORAGE_REGION
const Bucket = process.env.S3_STORAGE_BUCKET_NAME
if (!accessKeyId || !secretAccessKey || !region || !Bucket) {
if (!region || !Bucket) {
throw new Error('S3 storage configuration is missing')
}
const s3Client = new S3Client({
credentials: {
let credentials: S3ClientConfig['credentials'] | undefined
if (accessKeyId && secretAccessKey) {
credentials = {
accessKeyId,
secretAccessKey
},
}
}
const s3Client = new S3Client({
credentials,
region
})
return { s3Client, Bucket }