Skip to content

Commit 7903ad1

Browse files
committed
Add credentials to DynamoDB
1 parent c184cf1 commit 7903ad1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

backend/src/reports/reports.service.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ export class ReportsService {
2121

2222
try {
2323
this.dynamoClient = new DynamoDBClient({
24-
region: this.configService.get<string>('AWS_REGION', 'us-east-1')
24+
region: this.configService.get<string>('AWS_REGION', 'us-east-1'),
2525
});
2626
} 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');
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');
3030

31-
const clientConfig: any = { region };
31+
const clientConfig: any = { region };
3232

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);
33+
// Only add credentials if both values are present
34+
if (accessKeyId && secretAccessKey) {
35+
clientConfig.credentials = { accessKeyId, secretAccessKey };
3936
}
4037

38+
this.dynamoClient = new DynamoDBClient(clientConfig);
39+
}
40+
4141
this.tableName = this.configService.get<string>('DYNAMODB_REPORTS_TABLE', 'reports');
4242
}
4343

@@ -52,7 +52,9 @@ export class ReportsService {
5252
} catch (error: unknown) {
5353
console.error('DynamoDB Error Details:', JSON.stringify(error, null, 2));
5454
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.');
55+
throw new Error(
56+
'Invalid AWS credentials. Please check your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.',
57+
);
5658
}
5759
throw error;
5860
}

0 commit comments

Comments
 (0)