Skip to content

Commit d6ab5eb

Browse files
committed
Use @aws-sdk/credential-providers for smarter credential discovery that works with instance metadata
1 parent e2ff6ef commit d6ab5eb

3 files changed

Lines changed: 1018 additions & 152 deletions

File tree

packages/forms/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
},
3131
"dependencies": {
3232
"@ai-sdk/amazon-bedrock": "^3.0.30",
33+
"@aws-sdk/credential-providers": "^3.901.0",
34+
"@aws-sdk/types": "^3.901.0",
3335
"@flexion/forms-common": "workspace:*",
3436
"@flexion/forms-database": "workspace:*",
3537
"ai": "^5.0.59",

packages/forms/src/llm/providers/bedrock.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
2+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
3+
import type { AwsCredentialIdentityProvider } from '@aws-sdk/types';
24
import type { LanguageModel } from 'ai';
35

46
/**
@@ -7,6 +9,14 @@ import type { LanguageModel } from 'ai';
79
export type BedrockConfig = {
810
modelId: string;
911
region: string;
12+
/**
13+
* Optional credential provider for AWS authentication.
14+
* Defaults to fromNodeProviderChain() which automatically handles:
15+
* - Environment variables (local development)
16+
* - IAM roles (App Runner, ECS, EKS, EC2)
17+
* - Shared credentials file
18+
*/
19+
credentialProvider?: AwsCredentialIdentityProvider;
1020
};
1121

1222
/**
@@ -32,7 +42,11 @@ export const DEFAULT_BEDROCK_CONFIG: BedrockConfig = {
3242
export const createBedrockModel = (
3343
config: Partial<BedrockConfig> = {}
3444
): LanguageModel => {
35-
const { modelId, region } = { ...DEFAULT_BEDROCK_CONFIG, ...config };
36-
const bedrock = createAmazonBedrock({ region });
45+
const {
46+
modelId,
47+
region,
48+
credentialProvider = fromNodeProviderChain(),
49+
} = { ...DEFAULT_BEDROCK_CONFIG, ...config };
50+
const bedrock = createAmazonBedrock({ region, credentialProvider });
3751
return bedrock(modelId);
3852
};

0 commit comments

Comments
 (0)