-
Notifications
You must be signed in to change notification settings - Fork 634
Closed
Labels
bugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
When sending a request with @aws-sdk/client-bedrock-runtime
, the region number set during the request is incremented by 1, causing the process to fail.
For example, when preparing a client like the following:
const client = new BedrockRuntimeClient({
region: "ap-northeast-1",
credentials: {
accessKeyId: "{MY_ACCESS_KEY_ID}",
secretAccessKey: "{MY_SECRET_ACCESS_KEY}"
}
});
And executing the following code:
const prompt = 'Write a paragraph starting with: "Once upon a time..."';
const modelId = "apac.anthropic.claude-3-haiku-20240307-v1:0";
const payload = {
max_tokens: 1000,
messages: [
{
role: "user",
content: [{ type: "text", text: prompt }],
},
],
};
// Invoke Claude with the payload and wait for the response.
const command = new InvokeModelCommand({
contentType: "application/json",
body: JSON.stringify(payload),
modelId,
});
const apiResponse = await client.send(command);
// Decode and return the response(s)
const decodedResponseBody = new TextDecoder().decode(apiResponse.body);
/** @type {MessagesResponseBody} */
const responseBody = JSON.parse(decodedResponseBody);
const response = await responseBody.content[0].text;
console.log(response);
I encounter the following error:
AccessDeniedException: User: arn:aws:iam::${MY_AWS_ACCOUNT}:user/claude-access is not authorized to perform: bedrock:InvokeModel on resource: arn:aws:bedrock:ap-northeast-2::foundation-model/anthropic.claude-3-haiku-20240307-v1:0 because no identity-based policy allows the bedrock:InvokeModel action
My region is ap-northeast-1
, but the error shows ap-northeast-2
.
I have confirmed that the same phenomenon occurs under the following conditions:
- Using anthropic.claude-3-5-sonnet-20241022-v2:0 in us-east-1
- Using anthropic.claude-3-5-sonnet-20241022-v2:0 in ap-northeast-1
- Using anthropic.claude-3-5-sonnet-20241022-v2:0 in ap-northeast-2
- Using anthropic.claude-3-haiku-20240307-v1:0 in ap-northeast-1
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
bun v1.1.27 and node v23.5.0
Reproduction Steps
- import
@aws-sdk/client-bedrock-runtime
- create IAM user and access key granted the necessary privileges
- Replace MY_ACCESS_KEY_ID and MY_SECRET_ACCESS_KEY with your own and execute the following code.
import {
BedrockRuntimeClient,
InvokeModelCommand,
} from "@aws-sdk/client-bedrock-runtime";
const client = new BedrockRuntimeClient({
region: "ap-northeast-1",
credentials: {
accessKeyId: "{MY_ACCESS_KEY_ID}",
secretAccessKey: "{MY_SECRET_ACCESS_KEY}"
}
});
const prompt = 'Write a paragraph starting with: "Once upon a time..."';
const modelId = "apac.anthropic.claude-3-haiku-20240307-v1:0";
const payload = {
max_tokens: 1000,
messages: [
{
role: "user",
content: [{ type: "text", text: prompt }],
},
],
};
// Invoke Claude with the payload and wait for the response.
const command = new InvokeModelCommand({
contentType: "application/json",
body: JSON.stringify(payload),
modelId,
});
const apiResponse = await client.send(command);
// Decode and return the response(s)
const decodedResponseBody = new TextDecoder().decode(apiResponse.body);
/** @type {MessagesResponseBody} */
const responseBody = JSON.parse(decodedResponseBody);
const response = await responseBody.content[0].text;
console.log(response);
Observed Behavior
AccessDeniedException: User: arn:aws:iam::${MY_AWS_ACCOUNT}:user/claude-access is not authorized to perform: bedrock:InvokeModel on resource: arn:aws:bedrock:ap-northeast-2::foundation-model/anthropic.claude-3-haiku-20240307-v1:0 because no identity-based policy allows the bedrock:InvokeModel action
Expected Behavior
Access to Amazon Bedrock models in the appropriate region.
Possible Solution
No response
Additional Information/Context
No response
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.needs-triageThis issue or PR still needs to be triaged.This issue or PR still needs to be triaged.