Skip to content

Commit

Permalink
fix: get_bedrock_client() with AWS_PROFILE
Browse files Browse the repository at this point in the history
Function was incorrectly trying to pass the profile_name argument to
`session.client(...)` when it should only be sent to `Session(...)`
  • Loading branch information
athewsey committed Aug 3, 2023
1 parent cdf2d65 commit 9687d53
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions utils/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def get_bedrock_client(
target_region = region

print(f"Create new client\n Using region: {target_region}")
boto3_kwargs = {"region_name": target_region}
session_kwargs = {"region_name": target_region}
client_kwargs = {**session_kwargs}

profile_name = os.environ.get("AWS_PROFILE")
if profile_name:
print(f" Using profile: {profile_name}")
boto3_kwargs["profile_name"] = profile_name
session_kwargs["profile_name"] = profile_name

retry_config = Config(
region_name=target_region,
Expand All @@ -49,7 +50,7 @@ def get_bedrock_client(
"mode": "standard",
},
)
session = boto3.Session(**boto3_kwargs)
session = boto3.Session(**session_kwargs)

if assumed_role:
print(f" Using role: {assumed_role}", end='')
Expand All @@ -59,17 +60,17 @@ def get_bedrock_client(
RoleSessionName="langchain-llm-1"
)
print(" ... successful!")
boto3_kwargs["aws_access_key_id"] = response["Credentials"]["AccessKeyId"]
boto3_kwargs["aws_secret_access_key"] = response["Credentials"]["SecretAccessKey"]
boto3_kwargs["aws_session_token"] = response["Credentials"]["SessionToken"]
client_kwargs["aws_access_key_id"] = response["Credentials"]["AccessKeyId"]
client_kwargs["aws_secret_access_key"] = response["Credentials"]["SecretAccessKey"]
client_kwargs["aws_session_token"] = response["Credentials"]["SessionToken"]

if endpoint_url:
boto3_kwargs["endpoint_url"] = endpoint_url
client_kwargs["endpoint_url"] = endpoint_url

bedrock_client = session.client(
service_name="bedrock",
config=retry_config,
**boto3_kwargs
**client_kwargs
)

print("boto3 Bedrock client successfully created!")
Expand Down

0 comments on commit 9687d53

Please sign in to comment.