Skip to content

Commit c184cf1

Browse files
committed
Add credentials to DynamoDB
1 parent df51ed5 commit c184cf1

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

backend/src/config/configuration.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ export default () => ({
1010
secretsManager: {
1111
perplexityApiKeySecret: process.env.PERPLEXITY_API_KEY_SECRET_NAME || 'medical-reports-explainer/perplexity-api-key',
1212
},
13+
aws: {
14+
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
15+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
16+
}
1317
},
1418
perplexity: {
1519
apiBaseUrl: 'https://api.perplexity.ai',
1620
model: process.env.PERPLEXITY_MODEL || 'sonar',
1721
maxTokens: parseInt(process.env.PERPLEXITY_MAX_TOKENS || '2048', 10),
1822
},
19-
});
23+
});

backend/src/reports/reports.service.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,45 @@ export class ReportsService {
1717
private readonly tableName: string;
1818

1919
constructor(private configService: ConfigService) {
20-
this.dynamoClient = new DynamoDBClient({
21-
region: this.configService.get<string>('AWS_REGION', 'us-east-1'),
22-
});
23-
this.tableName = this.configService.get<string>('DYNAMODB_TABLE_NAME', 'reports');
20+
const region = this.configService.get<string>('AWS_REGION', 'us-east-1');
21+
22+
try {
23+
this.dynamoClient = new DynamoDBClient({
24+
region: this.configService.get<string>('AWS_REGION', 'us-east-1')
25+
});
26+
} catch (error: unknown) {
27+
console.error('DynamoDB Client Config:', JSON.stringify(error, null, 2));
28+
const accessKeyId = this.configService.get<string>('AWS_ACCESS_KEY_ID');
29+
const secretAccessKey = this.configService.get<string>('AWS_SECRET_ACCESS_KEY');
30+
31+
const clientConfig: any = { region };
32+
33+
// Only add credentials if both values are present
34+
if (accessKeyId && secretAccessKey) {
35+
clientConfig.credentials = { accessKeyId, secretAccessKey };
36+
}
37+
38+
this.dynamoClient = new DynamoDBClient(clientConfig);
39+
}
40+
41+
this.tableName = this.configService.get<string>('DYNAMODB_REPORTS_TABLE', 'reports');
2442
}
2543

2644
async findAll(): Promise<Report[]> {
2745
const command = new ScanCommand({
2846
TableName: this.tableName,
2947
});
3048

31-
const response = await this.dynamoClient.send(command);
32-
return (response.Items || []).map(item => unmarshall(item) as Report);
49+
try {
50+
const response = await this.dynamoClient.send(command);
51+
return (response.Items || []).map(item => unmarshall(item) as Report);
52+
} catch (error: unknown) {
53+
console.error('DynamoDB Error Details:', JSON.stringify(error, null, 2));
54+
if (error instanceof Error && error.name === 'UnrecognizedClientException') {
55+
throw new Error('Invalid AWS credentials. Please check your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.');
56+
}
57+
throw error;
58+
}
3359
}
3460

3561
async findLatest(queryDto: GetReportsQueryDto): Promise<Report[]> {

0 commit comments

Comments
 (0)