@@ -21,9 +21,6 @@ import os
2121import sys
2222import subprocess
2323import re
24- from threading import Thread
25-
26- from boto3 .session import Session
2724
2825PARENT_FOLDER = os .path .realpath (os .path .join (os .path .dirname (__file__ ), '..' ))
2926S3_VIRTUAL_ENDPOINT_HOSTNAME = 's3.localhost.localstack.cloud'
@@ -100,6 +97,7 @@ def prepare_environment():
10097
10198 env_dict .pop ('AWS_DATA_PATH' , None )
10299
100+ from boto3 .session import Session
103101 session = Session ()
104102 credentials = session .get_credentials ()
105103
@@ -236,14 +234,14 @@ def patch_awscli_libs():
236234 # get stack frame of caller
237235 curframe = inspect .currentframe ()
238236 calframe = inspect .getouterframes (curframe , 2 )
239- fname = calframe [1 ].filename
240237
241- # check if we are executing within the target method
242- is_target = (os .path .join ('cloudformation' , 'deploy.py' ) in fname
243- or os .path .join ('cloudformation' , 'package.py' ) in fname )
244- if is_target :
238+ # try to find the Cfn deploy or package frame
239+ cfn_frame = next (filter (lambda frame : os .path .join ('cloudformation' , 'deploy.py' ) in frame .filename
240+ or os .path .join ('cloudformation' , 'package.py' ) in frame .filename , calframe ), None )
241+
242+ if cfn_frame :
245243 if 'endpoint_url' not in kwargs :
246- args_passed = inspect .getargvalues (calframe [ 1 ] .frame ).locals
244+ args_passed = inspect .getargvalues (cfn_frame .frame ).locals
247245 kwargs ['endpoint_url' ] = args_passed ['parsed_args' ].s3_endpoint_url
248246 return create_client_orig (* args , ** kwargs )
249247
0 commit comments