()
| 48 | } |
| 49 | |
| 50 | async function createBedrockClient() { |
| 51 | const { BedrockClient } = await import('@aws-sdk/client-bedrock') |
| 52 | // Match the Anthropic Bedrock SDK's region behavior exactly: |
| 53 | // - Reads AWS_REGION or AWS_DEFAULT_REGION env vars (not AWS config files) |
| 54 | // - Falls back to 'us-east-1' if neither is set |
| 55 | // This ensures we query profiles from the same region the client will use |
| 56 | const region = getAWSRegion() |
| 57 | |
| 58 | const skipAuth = isEnvTruthy(process.env.CLAUDE_CODE_SKIP_BEDROCK_AUTH) |
| 59 | |
| 60 | const clientConfig: ConstructorParameters<typeof BedrockClient>[0] = { |
| 61 | region, |
| 62 | ...(process.env.ANTHROPIC_BEDROCK_BASE_URL && { |
| 63 | endpoint: process.env.ANTHROPIC_BEDROCK_BASE_URL, |
| 64 | }), |
| 65 | ...(await getAWSClientProxyConfig()), |
| 66 | ...(skipAuth && { |
| 67 | requestHandler: new ( |
| 68 | await import('@smithy/node-http-handler') |
| 69 | ).NodeHttpHandler(), |
| 70 | httpAuthSchemes: [ |
| 71 | { |
| 72 | schemeId: 'smithy.api#noAuth', |
| 73 | identityProvider: () => async () => ({}), |
| 74 | signer: new (await import('@smithy/core')).NoAuthSigner(), |
| 75 | }, |
| 76 | ], |
| 77 | httpAuthSchemeProvider: () => [{ schemeId: 'smithy.api#noAuth' }], |
| 78 | }), |
| 79 | } |
| 80 | |
| 81 | if (!skipAuth && !process.env.AWS_BEARER_TOKEN_BEDROCK) { |
| 82 | // Only refresh credentials if not using API key authentication |
| 83 | const cachedCredentials = await refreshAndGetAwsCredentials() |
| 84 | if (cachedCredentials) { |
| 85 | clientConfig.credentials = { |
| 86 | accessKeyId: cachedCredentials.accessKeyId, |
| 87 | secretAccessKey: cachedCredentials.secretAccessKey, |
| 88 | sessionToken: cachedCredentials.sessionToken, |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return new BedrockClient(clientConfig) |
| 94 | } |
| 95 | |
| 96 | export async function createBedrockRuntimeClient() { |
| 97 | const { BedrockRuntimeClient } = await import( |
no test coverage detected