Python
Client

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

  1. Get started by going to AWS Bedrock (opens in a new tab). Sign up for an account if you don't have one.
  2. 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.
  3. Request access to Anthropic's models.
  4. 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).
  5. Go to users and create a user.

Create a user

  1. 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).
  2. Click on the newly created user and click on add permissions.

Add permissions

  1. Click on create inline policy.

Inline policy

  1. Click on JSON

JSON

  1. The paste in the following:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "BedrockFullAccess",
      "Effect": "Allow",
      "Action": ["bedrock:*"],
      "Resource": "*"
    }
  ]
}
  1. Click next, give the policy any time bedrock is fine.

  2. Now create an access key

Access Key

  1. Select local code

Local code

  1. Done! You have an access key and a secret key. You are ready to use Anthropic's models.

Usage

from bedrock_anthropic import AnthropicBedrock
 
anthropic = AnthropicBedrock(
    access_key=os.getenv("AWS_ACCESS_KEY"),
    secret_key=os.getenv("AWS_SECRET_KEY"),
    region=os.getenv("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

  1. Follow all the steps above until step 13.
  2. Follow this guide (opens in a new tab) to install the AWS CLI.
  3. Follow this guide (opens in a new tab) to login to the CLI.
  4. You're good to go!

Usage

from bedrock_anthropic import AnthropicBedrock
 
anthropic = 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

  1. Follow all the steps above until step 13.
  2. Ensure that the current user has an assumed role (opens in a new tab).
  3. Done, just add the assumed role to the python client.

Usage

from bedrock_anthropic import AnthropicBedrock
 
anthropic = AnthropicBedrock(
    assumed_role = os.getenv("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

from bedrock_anthropic import AnthropicBedrock
 
anthropic = AnthropicBedrock(
    region=os.getenv("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

from bedrock_anthropic import AnthropicBedrock
 
anthropic = AnthropicBedrock(
    profile=os.getenv["AWS_PROFILE"]
)

This assumes you have the AWS CLI setup.