Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #537: Update AWS region logic for flexibility and defaults #669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/anthropic/lib/bedrock/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from typing import Any, Union, Mapping, TypeVar
from typing_extensions import Self, override
import boto3

import httpx

Expand Down Expand Up @@ -116,9 +117,8 @@ def __init__(

self.aws_access_key = aws_access_key

if aws_region is None:
aws_region = os.environ.get("AWS_REGION") or "us-east-1"
self.aws_region = aws_region
self.aws_region = aws_region or os.environ.get("AWS_REGION") or self.get_region_from_boto3() or "us-east-1"


self.aws_session_token = aws_session_token

Expand Down Expand Up @@ -167,6 +167,12 @@ def _prepare_request(self, request: httpx.Request) -> None:
)
request.headers.update(headers)

def get_region_from_boto3(
self
) -> str | None:
session = boto3.Session()
return session.region_name

def copy(
self,
*,
Expand Down