11import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock' ;
2+ import { fromNodeProviderChain } from '@aws-sdk/credential-providers' ;
3+ import type { AwsCredentialIdentityProvider } from '@aws-sdk/types' ;
24import type { LanguageModel } from 'ai' ;
35
46/**
@@ -7,6 +9,14 @@ import type { LanguageModel } from 'ai';
79export 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 = {
3242export 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