Client
There are three ways to sign in using AWS Bedrock, the most intuitive way is with an access_key
and a secret_key
. You can also automatically sign in with your aws credentials
if you are signed in using the aws cli. Finally, you can sign in using AWS profile.
Access Key and Secret Key
Access key and secret key are the preferred ways to interact with this library. Note that the access key is different from that in the anthropic console. This SDK is soley focused on AWS Bedrock.
Steps
- Get started by going to AWS Bedrock (opens in a new tab). Sign up for an account if you don't have one.
- Go to anthropics models in the AWS bedrock console. If you're on
us-east-1
you can following this link (opens in a new tab). If not, change to the region on are on, or just go through the console. - Request access to Anthropic's models.
- Once you are approved (should be very quick), got to the IAM dashboard in AWS. If you're on
us-east-1
use the following link (opens in a new tab). - Go to users and create a user.
- Enter a user name and create a user. (You don't have to add them to user groups or anything, but if you want to add them to an admin user group that's great as well).
- Click on the newly created user and click on add permissions.
- Click on create inline policy.
- Click on JSON
- The paste in the following:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BedrockFullAccess",
"Effect": "Allow",
"Action": ["bedrock:*"],
"Resource": "*"
}
]
}
-
Click next, give the policy any time
bedrock
is fine. -
Now create an access key
- Select local code
- Done! You have an access key and a secret key. You are ready to use Anthropic's models.
Usage
import AnthropicBedrock from "anthropic-bedrock";
anthropic = new AnthropicBedrock({
access_key: process.env["AWS_ACCESS_KEY"],
secret_key: process.env["AWS_SECRET_KEY"],
region: process.env["AWS_REGION"],
});
AWS CLI
The AWS CLI allows you to abstract authentication. It does all the authentication for you if you are logged in using the CLI.
Steps
- Follow all the steps above until step 13.
- Follow this guide (opens in a new tab) to install the AWS CLI.
- Follow this guide (opens in a new tab) to login to the CLI.
- You're good to go!
Usage
import AnthropicBedrock from "anthropic-bedrock";
anthropic = new AnthropicBedrock();
Specific Role
In the case that your company has a specific role or seperate IAM Role to access Bedrock, you can specify the assume role manually. You must also ensure that the user has the permissions to assume (opens in a new tab) such role.
Steps
- Follow all the steps above until step 13.
- Ensure that the current user has an assumed role (opens in a new tab).
- Done, just add the assumed role to the python client.
Example
import AnthropicBedrock from "anthropic-bedrock";
anthropic = new AnthropicBedrock({
assumed_role: process.env["AWS_ASSUMED_ROLE"],
});
This assumes you have the AWS CLI setup.
Region
If you have a differen region from where Bedrock is setup, you can specify the region in the client.
Example
import AnthropicBedrock from "anthropic-bedrock";
anthropic = new AnthropicBedrock({
region: process.env["AWS_DEFAULT_REGION"],
});
This assumes you have the AWS CLI setup.
Specific Profile
If you have multiple profiles on your AWS CLI, you can specify the profile you want to use.
Example
import AnthropicBedrock from "anthropic-bedrock";
anthropic = new AnthropicBedrock({
profile: process.env["AWS_PROFILE"],
});
This assumes you have the AWS CLI setup.