Skip to content

Commit a996488

Browse files
authored
Fix: Bedrock Profiles (RooCodeInc#1751)
* fix-bedrock-profiles * fix-bedrock-profiles * resolve linting issue * fixes * resolve using var * add changeset * update changeset
1 parent 0434b5c commit a996488

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

.changeset/orange-eels-unite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Fix AWS Bedrock Profiles. When configuring the AnthropicBedrock Client you must pass AWS credentials in a specific way, otherwise the client will default to reading credentials from the default AWS profile.

src/api/providers/bedrock.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,50 @@ import { fromIni } from "@aws-sdk/credential-providers"
88
// https://docs.anthropic.com/en/api/claude-on-amazon-bedrock
99
export class AwsBedrockHandler implements ApiHandler {
1010
private options: ApiHandlerOptions
11-
private client: AnthropicBedrock
11+
private client: AnthropicBedrock | any
12+
private initializationPromise: Promise<void>
1213

1314
constructor(options: ApiHandlerOptions) {
1415
this.options = options
16+
this.initializationPromise = this.initializeClient()
17+
}
1518

16-
const clientConfig: any = {
19+
private async initializeClient() {
20+
let clientConfig: any = {
1721
awsRegion: this.options.awsRegion || "us-east-1",
1822
}
19-
20-
if (this.options.awsUseProfile) {
21-
// Use profile-based credentials if enabled
22-
if (this.options.awsProfile) {
23-
clientConfig.credentials = fromIni({
24-
profile: this.options.awsProfile,
25-
})
26-
} else {
27-
// Use default profile if no specific profile is set
28-
clientConfig.credentials = fromIni()
29-
}
30-
} else if (this.options.awsAccessKey && this.options.awsSecretKey) {
31-
// Use direct credentials if provided
32-
clientConfig.awsAccessKey = this.options.awsAccessKey
33-
clientConfig.awsSecretKey = this.options.awsSecretKey
34-
if (this.options.awsSessionToken) {
35-
clientConfig.awsSessionToken = this.options.awsSessionToken
23+
try {
24+
if (this.options.awsUseProfile) {
25+
// Use profile-based credentials if enabled
26+
// Use named profile, defaulting to 'default' if not specified
27+
var credentials: any
28+
if (this.options.awsProfile) {
29+
credentials = await fromIni({
30+
profile: this.options.awsProfile,
31+
ignoreCache: true,
32+
})()
33+
} else {
34+
credentials = await fromIni({
35+
ignoreCache: true,
36+
})()
37+
}
38+
clientConfig.awsAccessKey = credentials.accessKeyId
39+
clientConfig.awsSecretKey = credentials.secretAccessKey
40+
clientConfig.awsSessionToken = credentials.sessionToken
41+
} else if (this.options.awsAccessKey && this.options.awsSecretKey) {
42+
// Use direct credentials if provided
43+
clientConfig.awsAccessKey = this.options.awsAccessKey
44+
clientConfig.awsSecretKey = this.options.awsSecretKey
45+
if (this.options.awsSessionToken) {
46+
clientConfig.awsSessionToken = this.options.awsSessionToken
47+
}
3648
}
49+
} catch (error) {
50+
console.error("Failed to initialize Bedrock client:", error)
51+
throw error
52+
} finally {
53+
this.client = new AnthropicBedrock(clientConfig)
3754
}
38-
39-
this.client = new AnthropicBedrock(clientConfig)
4055
}
4156

4257
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {

0 commit comments

Comments
 (0)