@@ -74,45 +74,37 @@ def get_bedrock_client(
74
74
75
75
76
76
def get_bedrock_client_v1 (
77
- assumed_role : Optional [str ] = None ,
78
- service_name : str = "bedrock-runtime" ,
79
- region : str = "us-east-1" ,
80
- read_timeout : int = 5000 ,
81
- connect_timeout : int = 5000 ,
82
- retries : Dict = {"max_attempts" : 10 },
83
- ):
84
- if region is None :
85
- target_region = os .environ .get ("AWS_REGION" , os .environ .get ("AWS_DEFAULT_REGION" ))
86
- else :
87
- target_region = region
88
-
89
- boto_config = Config (
90
- read_timeout = read_timeout , connect_timeout = connect_timeout , retries = retries
91
- )
77
+ assumed_role : Optional [str ] = None ,
78
+ service_name : str = "bedrock-runtime" ,
79
+ region : Optional [str ] = "us-east-1" ,
80
+ read_timeout : int = 5000 ,
81
+ connect_timeout : int = 5000 ,
82
+ retries : Dict = {"max_attempts" : 10 },
83
+ ):
84
+ if region is None :
85
+ target_region = os .environ .get ("AWS_REGION" , os .environ .get ("AWS_DEFAULT_REGION" ))
86
+ else :
87
+ target_region = region
92
88
93
- if target_region is None :
94
- raise ValueError (
95
- "region environment variable is not set."
96
- )
97
-
98
- if assumed_role :
99
- session = boto3 .Session (region_name = target_region )
100
- # Assume role and get credentials
101
- sts = session .client ("sts" )
102
- creds = sts .assume_role (RoleArn = str (assumed_role ),RoleSessionName = "crfm-helm" )["Credentials" ]
103
- session = Session (
104
- aws_access_key_id = creds ["AccessKeyId" ],
105
- aws_secret_access_key = creds ["SecretAccessKey" ],
106
- )
107
- return session .client (
108
- service_name = service_name ,
109
- region_name = target_region ,
110
- config = boto_config ,
111
- )
112
-
113
- # default to instance role to get the aws credentials or aws configured credentials
114
- return boto3 .client (
89
+ boto_config = Config (read_timeout = read_timeout , connect_timeout = connect_timeout , retries = retries )
90
+
91
+ if target_region is None :
92
+ raise ValueError ("region environment variable is not set." )
93
+
94
+ if assumed_role :
95
+ session = boto3 .Session (region_name = target_region )
96
+ # Assume role and get credentials
97
+ sts = session .client ("sts" )
98
+ creds = sts .assume_role (RoleArn = str (assumed_role ), RoleSessionName = "crfm-helm" )["Credentials" ]
99
+ session = Session (
100
+ aws_access_key_id = creds ["AccessKeyId" ],
101
+ aws_secret_access_key = creds ["SecretAccessKey" ],
102
+ )
103
+ return session .client (
115
104
service_name = service_name ,
116
105
region_name = target_region ,
117
- config = boto_config
106
+ config = boto_config ,
118
107
)
108
+
109
+ # default to instance role to get the aws credentials or aws configured credentials
110
+ return boto3 .client (service_name = service_name , region_name = target_region , config = boto_config )
0 commit comments