Skip to content

Commit ca1f9c9

Browse files
committed
feat: Enhance AWS client configuration to support optional credentials in DocumentProcessorController and ReportsService
1 parent e38f70b commit ca1f9c9

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

backend/src/document-processor/controllers/document-processor.controller.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,23 @@ export class DocumentProcessorController {
186186

187187
const region = this.configService.get<string>('aws.region') || 'us-east-1';
188188

189-
const s3Client = new S3Client({ region });
189+
// Get optional AWS credentials if they exist
190+
const accessKeyId = this.configService.get<string>('aws.aws.accessKeyId');
191+
const secretAccessKey = this.configService.get<string>('aws.aws.secretAccessKey');
192+
const sessionToken = this.configService.get<string>('aws.aws.sessionToken');
193+
194+
// Create S3 client with credentials if they exist
195+
const s3ClientOptions: any = { region };
196+
197+
if (accessKeyId && secretAccessKey) {
198+
s3ClientOptions.credentials = {
199+
accessKeyId,
200+
secretAccessKey,
201+
...(sessionToken && { sessionToken }),
202+
};
203+
}
204+
205+
const s3Client = new S3Client(s3ClientOptions);
190206

191207
const command = new GetObjectCommand({
192208
Bucket: bucketName,

backend/src/reports/reports.service.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@ export class ReportsService {
2727
private readonly logger = new Logger(ReportsService.name);
2828

2929
constructor(private configService: ConfigService) {
30-
const region = this.configService.get<string>('AWS_REGION', 'us-east-1');
31-
const accessKeyId = this.configService.get<string>('AWS_ACCESS_KEY_ID');
32-
const secretAccessKey = this.configService.get<string>('AWS_SECRET_ACCESS_KEY');
30+
const region = this.configService.get<string>('aws.region') || 'us-east-1';
3331

34-
// Prepare client configuration
35-
const clientConfig: any = { region };
32+
// Get optional AWS credentials if they exist
33+
const accessKeyId = this.configService.get<string>('aws.aws.accessKeyId');
34+
const secretAccessKey = this.configService.get<string>('aws.aws.secretAccessKey');
35+
const sessionToken = this.configService.get<string>('aws.aws.sessionToken');
36+
37+
const clientOptions: any = { region };
3638

37-
// Only add credentials if both values are present
3839
if (accessKeyId && secretAccessKey) {
39-
clientConfig.credentials = { accessKeyId, secretAccessKey };
40+
clientOptions.credentials = {
41+
accessKeyId,
42+
secretAccessKey,
43+
...(sessionToken && { sessionToken }),
44+
};
4045
}
4146

4247
try {
43-
this.dynamoClient = new DynamoDBClient(clientConfig);
48+
this.dynamoClient = new DynamoDBClient(clientOptions);
4449
} catch (error: unknown) {
4550
this.logger.error('Failed to initialize DynamoDB client:', error);
4651
throw new InternalServerErrorException('Failed to initialize database connection');

0 commit comments

Comments
 (0)