-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use one method to get boto client for aws bedrock
- Loading branch information
Showing
4 changed files
with
30 additions
and
22 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
api/core/model_runtime/model_providers/bedrock/get_bedrock_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import boto3 | ||
from botocore.config import Config | ||
|
||
|
||
def get_bedrock_client(service_name, credentials=None): | ||
client_config = Config(region_name=credentials["aws_region"]) | ||
aws_access_key_id = credentials["aws_access_key_id"], | ||
aws_secret_access_key = credentials["aws_secret_access_key"] | ||
if aws_access_key_id and aws_secret_access_key: | ||
# 使用 AKSK 方式 | ||
client = boto3.client( | ||
service_name=service_name, | ||
config=client_config, | ||
aws_access_key_id=aws_access_key_id, | ||
aws_secret_access_key=aws_secret_access_key | ||
) | ||
else: | ||
# 使用 IAM 角色方式 | ||
client = boto3.client(service_name=service_name, config=client_config) | ||
|
||
return client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters