@@ -56,7 +56,7 @@ def check_aws_environment():
56
56
"""
57
57
try :
58
58
# Try to create a boto3 client and make a simple API call
59
- sts = boto3 .client ("sts" )
59
+ sts = boto3 .client ("sts" , region_name = get_current_region () )
60
60
response = sts .get_caller_identity ()
61
61
logger .info ("AWS environment is properly configured." )
62
62
account_id = response ["Account" ]
@@ -69,7 +69,7 @@ def check_aws_environment():
69
69
70
70
71
71
def get_account_id ():
72
- sts_client = boto3 .client ("sts" )
72
+ sts_client = boto3 .client ("sts" , region_name = get_current_region () )
73
73
account_id = sts_client .get_caller_identity ()["Account" ]
74
74
return account_id
75
75
@@ -123,7 +123,7 @@ def get_role_create_template(
123
123
124
124
125
125
def get_stack_info (stack_name ):
126
- cf = boto3 .client ("cloudformation" )
126
+ cf = boto3 .client ("cloudformation" , region_name = get_current_region () )
127
127
stack_info = cf .describe_stacks (StackName = stack_name )["Stacks" ][0 ]
128
128
parameters = {}
129
129
for parameter in stack_info ["Parameters" ]:
@@ -134,7 +134,7 @@ def get_stack_info(stack_name):
134
134
135
135
def check_stack_exists (stack_name ):
136
136
try :
137
- cf = boto3 .client ("cloudformation" )
137
+ cf = boto3 .client ("cloudformation" , region_name = get_current_region () )
138
138
cf .describe_stacks (StackName = stack_name )
139
139
return True
140
140
except ClientError as e :
@@ -150,7 +150,7 @@ def check_stack_status(stack_name) -> StackStatus:
150
150
is_stack_exist = True
151
151
stack_info = {}
152
152
try :
153
- cf = boto3 .client ("cloudformation" )
153
+ cf = boto3 .client ("cloudformation" , region_name = get_current_region () )
154
154
stack_info = cf .describe_stacks (StackName = stack_name )["Stacks" ][0 ]
155
155
except ClientError as e :
156
156
if e .response ["Error" ][
@@ -163,7 +163,7 @@ def check_stack_status(stack_name) -> StackStatus:
163
163
164
164
165
165
def get_pipeline_stages (pipeline_name : str ) -> list [str ]:
166
- client = boto3 .client ("codepipeline" )
166
+ client = boto3 .client ("codepipeline" , region_name = get_current_region () )
167
167
response = client .get_pipeline_state (name = pipeline_name )
168
168
stages = [i ["stageName" ] for i in response ["stageStates" ]]
169
169
return stages
@@ -173,7 +173,7 @@ def get_pipeline_execution_info(
173
173
pipeline_name : str , pipeline_execution_id : str , client = None
174
174
):
175
175
176
- client = client or boto3 .client ("codepipeline" )
176
+ client = client or boto3 .client ("codepipeline" , region_name = get_current_region () )
177
177
execution_info = client .get_pipeline_execution (
178
178
pipelineName = pipeline_name , pipelineExecutionId = pipeline_execution_id
179
179
)["pipelineExecution" ]
@@ -187,7 +187,7 @@ def get_pipeline_active_executions(
187
187
filter_stoped = True ,
188
188
filter_failed = True ,
189
189
) -> list [dict ]:
190
- client = client or boto3 .client ("codepipeline" )
190
+ client = client or boto3 .client ("codepipeline" , region_name = get_current_region () )
191
191
try :
192
192
stage_states = client .get_pipeline_state (name = pipeline_name )[
193
193
"stageStates"
@@ -264,7 +264,7 @@ def get_pipeline_active_executions(
264
264
265
265
266
266
def get_model_stacks ():
267
- cf = boto3 .client ("cloudformation" )
267
+ cf = boto3 .client ("cloudformation" , region_name = get_current_region () )
268
268
stacks = cf .list_stacks (
269
269
StackStatusFilter = [
270
270
"CREATE_COMPLETE" ,
@@ -322,21 +322,21 @@ def get_model_stacks():
322
322
323
323
324
324
def get_model_stack_info (model_stack_name : str ):
325
- cf = boto3 .client ("cloudformation" )
325
+ cf = boto3 .client ("cloudformation" , region_name = get_current_region () )
326
326
stack_info = cf .describe_stacks (StackName = model_stack_name )["Stacks" ][0 ]
327
327
return stack_info
328
328
329
329
330
330
def s3_bucket_version (bucket , s3_key ):
331
- s3_client = boto3 .client ("s3" )
331
+ s3_client = boto3 .client ("s3" , region_name = get_current_region () )
332
332
version_id : str = s3_client .head_object (Bucket = bucket , Key = s3_key )[
333
333
"VersionId"
334
334
]
335
335
return version_id
336
336
337
337
338
338
def check_stack_exist_and_complete (stack_name : str ):
339
- client = boto3 .client ("cloudformation" )
339
+ client = boto3 .client ("cloudformation" , region_name = get_current_region () )
340
340
try :
341
341
response = client .describe_stacks (StackName = stack_name )
342
342
stack_status = response ["Stacks" ][0 ]["StackStatus" ]
@@ -357,7 +357,7 @@ def monitor_stack(stack_name):
357
357
response = get_stack_info (stack_name = stack_name )
358
358
stack_id = response ["StackId" ]
359
359
seen_events = set ()
360
- cloudformation = boto3 .client ("cloudformation" )
360
+ cloudformation = boto3 .client ("cloudformation" , region_name = get_current_region () )
361
361
# Determine if this is a create or update operation
362
362
while True :
363
363
events = cloudformation .describe_stack_events (StackName = stack_id )[
@@ -398,7 +398,7 @@ def monitor_stack(stack_name):
398
398
399
399
400
400
def monitor_pipeline (pipeline_name , pipeline_execution_id ):
401
- client = boto3 .client ("codepipeline" )
401
+ client = boto3 .client ("codepipeline" , region_name = get_current_region () )
402
402
while True :
403
403
response = client .get_pipeline_state (name = pipeline_name )
404
404
for stage in response ["stageStates" ]:
@@ -435,7 +435,7 @@ def get_sagemaker_instance_quota(instance_type: str) -> float:
435
435
ValueError: If the instance type doesn't have a corresponding quota code
436
436
ClientError: If there's an error calling AWS Service Quotas
437
437
"""
438
- service_quota_client = boto3 .client ("service-quotas" )
438
+ service_quota_client = boto3 .client ("service-quotas" , region_name = get_current_region () )
439
439
440
440
quota_code = ServiceQuotaCode .get_service_quota_code (instance_type )
441
441
response = service_quota_client .get_service_quota (
@@ -459,7 +459,7 @@ def get_sagemaker_instance_count_by_type(instance_type: str):
459
459
list: List of endpoint names using this instance type
460
460
"""
461
461
# Initialize SageMaker client
462
- sagemaker_client = boto3 .client ("sagemaker" )
462
+ sagemaker_client = boto3 .client ("sagemaker" , region_name = get_current_region () )
463
463
464
464
sagemaker_instance_type = InstanceType .convert_instance_type_to_sagemaker (
465
465
instance_type
@@ -566,7 +566,7 @@ def get_current_region():
566
566
567
567
568
568
def get_aws_account_id ():
569
- sts = boto3 .client ("sts" )
569
+ sts = boto3 .client ("sts" , region_name = get_current_region () )
570
570
response = sts .get_caller_identity ()
571
571
account_id = response ["Account" ]
572
572
return account_id
0 commit comments