def __init__(self, boto_session=None, sagemaker_client=None, sagemaker_runtime_client=None): """Initialize a SageMaker ``Session``. Args: boto_session (boto3.session.Session): The underlying Boto3 session which AWS service calls are delegated to (default: None). If not provided, one is created with default AWS configuration chain. sagemaker_client (boto3.SageMaker.Client): Client which makes Amazon SageMaker service calls other than ``InvokeEndpoint`` (default: None). Estimators created using this ``Session`` use this client. If not provided, one will be created using this instance's ``boto_session``. sagemaker_runtime_client (boto3.SageMakerRuntime.Client): Client which makes ``InvokeEndpoint`` calls to Amazon SageMaker (default: None). Predictors created using this ``Session`` use this client. If not provided, one will be created using this instance's ``boto_session``. """ self._default_bucket = None self.boto_session = boto_session or boto3.Session() region = self.boto_session.region_name if region is None: raise ValueError( 'Must setup local AWS configuration with a region supported by SageMaker.' ) self.sagemaker_client = sagemaker_client or self.boto_session.client( 'sagemaker') prepend_user_agent(self.sagemaker_client) self.sagemaker_runtime_client = sagemaker_runtime_client or self.boto_session.client( 'runtime.sagemaker') prepend_user_agent(self.sagemaker_runtime_client)
def _initialize(self, boto_session, sagemaker_client, sagemaker_runtime_client): """Initialize this SageMaker Session. Creates or uses a boto_session, sagemaker_client and sagemaker_runtime_client. Sets the region_name. """ self.boto_session = boto_session or boto3.Session() self._region_name = self.boto_session.region_name if self._region_name is None: raise ValueError('Must setup local AWS configuration with a region supported by SageMaker.') self.sagemaker_client = sagemaker_client or self.boto_session.client('sagemaker') prepend_user_agent(self.sagemaker_client) self.sagemaker_runtime_client = sagemaker_runtime_client or self.boto_session.client('runtime.sagemaker') prepend_user_agent(self.sagemaker_runtime_client) self.local_mode = False