Skip to content

Commit dccdb97

Browse files
authored
Merge pull request #59 from ModusCreateOrg/ADE-152
[ADE-152] Refactor aws-bedrock.service.ts to streamline AWS client configuration
2 parents 7820aaa + 6261b22 commit dccdb97

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

backend/src/document-processor/services/aws-bedrock.service.ts

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,17 @@ Document text:
147147
const secretAccessKey = this.configService.get<string>('aws.aws.secretAccessKey');
148148
const sessionToken = this.configService.get<string>('aws.aws.sessionToken');
149149

150-
if (!region || !accessKeyId || !secretAccessKey) {
151-
throw new Error('Missing required AWS configuration');
150+
const clientConfig: any = { region };
151+
152+
if (accessKeyId && secretAccessKey) {
153+
clientConfig.credentials = {
154+
accessKeyId,
155+
secretAccessKey,
156+
...(sessionToken && { sessionToken }),
157+
};
152158
}
153159

154-
const credentials = this.createCredentialsObject(accessKeyId, secretAccessKey, sessionToken);
155-
156-
const client = new BedrockRuntimeClient({
157-
region,
158-
credentials,
159-
});
160+
const client = new BedrockRuntimeClient(clientConfig);
160161

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

168-
/**
169-
* Create AWS credentials object with proper typing
170-
*/
171-
private createCredentialsObject(
172-
accessKeyId: string,
173-
secretAccessKey: string,
174-
sessionToken?: string,
175-
): {
176-
accessKeyId: string;
177-
secretAccessKey: string;
178-
sessionToken?: string;
179-
} {
180-
const credentials = {
181-
accessKeyId,
182-
secretAccessKey,
183-
};
184-
185-
if (sessionToken) {
186-
return { ...credentials, sessionToken };
187-
}
188-
189-
return credentials;
190-
}
191-
192169
/**
193170
* Configure the model ID from configuration with fallback
194171
*/

0 commit comments

Comments
 (0)