Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 9 additions & 32 deletions backend/src/document-processor/services/aws-bedrock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,17 @@ Document text:
const secretAccessKey = this.configService.get<string>('aws.aws.secretAccessKey');
const sessionToken = this.configService.get<string>('aws.aws.sessionToken');

if (!region || !accessKeyId || !secretAccessKey) {
throw new Error('Missing required AWS configuration');
const clientConfig: any = { region };

if (accessKeyId && secretAccessKey) {
clientConfig.credentials = {
accessKeyId,
secretAccessKey,
...(sessionToken && { sessionToken }),
};
}

const credentials = this.createCredentialsObject(accessKeyId, secretAccessKey, sessionToken);

const client = new BedrockRuntimeClient({
region,
credentials,
});
const client = new BedrockRuntimeClient(clientConfig);

this.logger.log(
`AWS client initialized with region ${region} and credentials ${accessKeyId ? '(provided)' : '(missing)'}, session token ${sessionToken ? '(provided)' : '(not provided)'}`,
Expand All @@ -165,30 +166,6 @@ Document text:
return client;
}

/**
* Create AWS credentials object with proper typing
*/
private createCredentialsObject(
accessKeyId: string,
secretAccessKey: string,
sessionToken?: string,
): {
accessKeyId: string;
secretAccessKey: string;
sessionToken?: string;
} {
const credentials = {
accessKeyId,
secretAccessKey,
};

if (sessionToken) {
return { ...credentials, sessionToken };
}

return credentials;
}

/**
* Configure the model ID from configuration with fallback
*/
Expand Down