Merge pull request #4651 from josephpage/feat/aws-credentials-chain
feat: retrieve AWS credentials from Env and ECS/EC2 instance
This commit is contained in:
commit
c4279fc962
4 changed files with 16 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
|
||||
import { fromIni } from "@aws-sdk/credential-providers";
|
||||
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
||||
import Bedrock from "./Bedrock.js";
|
||||
import { ChatMessage, Chunk, CompletionOptions, UserChatMessage } from "../../index.js";
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ jest.mock("@aws-sdk/client-bedrock-runtime", () => ({
|
|||
|
||||
// Mock credential provider
|
||||
jest.mock("@aws-sdk/credential-providers", () => ({
|
||||
fromIni: jest.fn().mockImplementation(() => async () => ({
|
||||
fromNodeProviderChain: jest.fn().mockImplementation(() => async () => ({
|
||||
accessKeyId: "test-access-key",
|
||||
secretAccessKey: "test-secret-key",
|
||||
sessionToken: "test-session-token",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {
|
|||
ConverseStreamCommand,
|
||||
InvokeModelCommand,
|
||||
} from "@aws-sdk/client-bedrock-runtime";
|
||||
import { fromIni } from "@aws-sdk/credential-providers";
|
||||
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
||||
|
||||
import {
|
||||
ChatMessage,
|
||||
|
|
@ -328,7 +328,7 @@ class Bedrock extends BaseLLM {
|
|||
|
||||
private async _getCredentials() {
|
||||
try {
|
||||
return await fromIni({
|
||||
return await fromNodeProviderChain({
|
||||
profile: this.profile,
|
||||
ignoreCache: true,
|
||||
})();
|
||||
|
|
@ -336,7 +336,7 @@ class Bedrock extends BaseLLM {
|
|||
console.warn(
|
||||
`AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`,
|
||||
);
|
||||
return await fromIni()();
|
||||
return await fromNodeProviderChain()();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {
|
||||
BedrockRuntimeClient,
|
||||
InvokeModelWithResponseStreamCommand,
|
||||
BedrockRuntimeClient,
|
||||
InvokeModelWithResponseStreamCommand,
|
||||
} from "@aws-sdk/client-bedrock-runtime";
|
||||
import { fromIni } from "@aws-sdk/credential-providers";
|
||||
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
||||
|
||||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { BaseLLM } from "../index.js";
|
||||
|
|
@ -77,7 +77,7 @@ class BedrockImport extends BaseLLM {
|
|||
|
||||
private async _getCredentials() {
|
||||
try {
|
||||
return await fromIni({
|
||||
return await fromNodeProviderChain({
|
||||
profile: this.profile,
|
||||
ignoreCache: true,
|
||||
})();
|
||||
|
|
@ -85,7 +85,7 @@ class BedrockImport extends BaseLLM {
|
|||
console.warn(
|
||||
`AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`,
|
||||
);
|
||||
return await fromIni()();
|
||||
return await fromNodeProviderChain()();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import {
|
||||
InvokeEndpointCommand,
|
||||
InvokeEndpointWithResponseStreamCommand,
|
||||
SageMakerRuntimeClient,
|
||||
InvokeEndpointCommand,
|
||||
InvokeEndpointWithResponseStreamCommand,
|
||||
SageMakerRuntimeClient,
|
||||
} from "@aws-sdk/client-sagemaker-runtime";
|
||||
import { fromIni } from "@aws-sdk/credential-providers";
|
||||
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
||||
|
||||
// @ts-ignore
|
||||
import jinja from "jinja-js";
|
||||
|
|
@ -130,14 +130,14 @@ class SageMaker extends BaseLLM {
|
|||
|
||||
private async _getCredentials() {
|
||||
try {
|
||||
return await fromIni({
|
||||
return await fromNodeProviderChain({
|
||||
profile: this.profile,
|
||||
})();
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
`AWS profile with name ${this.profile} not found in ~/.aws/credentials, using default profile`,
|
||||
);
|
||||
return await fromIni()();
|
||||
return await fromNodeProviderChain()();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue