From a42d1db7cac0f65908e55b1b13b4a11cfba7e47b Mon Sep 17 00:00:00 2001 From: Amarjeet LNU Date: Mon, 14 Sep 2026 14:35:10 -0700 Subject: [PATCH 1/4] fix: SageMakerClient honors the passed boto3 session and config SageMakerClient was a process-wide singleton: whichever instance was created first was returned to every later caller, and the session passed on those later calls was silently ignored. Any code path that created a client with default-chain credentials before the user's own session was seen (bare SageMakerClient() calls, a second profile, an assumed role) then signed every control-plane call with the wrong identity. This is the residual half of #5986 and the cause of the cross-account "RoleArn: Cross-account pass role is not allowed" failure in #6069. The config argument was also computed and then discarded, so caller timeouts and retry settings never reached the boto3 clients. Replace the singleton with a cache keyed on the constructor arguments. An explicit session (or region/config) always yields a client built from exactly those arguments; SageMakerClient() with no arguments keeps returning the process default, and the first instance created still becomes that default, so the configure-once pattern used by generated stop() methods and existing callers is unchanged. Keyed entries are a small LRU (32) so a service minting a session per request does not retain every session and its four boto3 clients; the default entry is never evicted. Construction is serialized with a lock so concurrent first callers share one instance. The caller's config is merged into the client config with the SDK user-agent suffix appended rather than replacing it. SingletonMeta is left in place for CloudWatchLogsClient. Fixes #5986 Fixes #6069 --- X-AI-Prompt: Fix the SageMakerClient singleton so an explicitly passed boto3 session is honored (#5986/#6069) X-AI-Tool: Kiro --- .../src/sagemaker/core/utils/utils.py | 98 +++++++- .../tests/unit/test_sagemaker_client.py | 230 ++++++++++++++++++ 2 files changed, 320 insertions(+), 8 deletions(-) create mode 100644 sagemaker-core/tests/unit/test_sagemaker_client.py diff --git a/sagemaker-core/src/sagemaker/core/utils/utils.py b/sagemaker-core/src/sagemaker/core/utils/utils.py index 9f916902f4..d662408821 100644 --- a/sagemaker-core/src/sagemaker/core/utils/utils.py +++ b/sagemaker-core/src/sagemaker/core/utils/utils.py @@ -16,6 +16,8 @@ import os import re import subprocess +import threading +from collections import OrderedDict from boto3.session import Session from botocore.config import Config @@ -333,15 +335,92 @@ def __call__(cls, *args, **kwargs): return cls._instances[cls] -class SageMakerClient(metaclass=SingletonMeta): +class _ClientCacheMeta(type): """ - A singleton class for creating a SageMaker client. + Metaclass that caches instances per constructor arguments. + + A call with no arguments returns the process-wide default instance, creating it + from the default credential chain if none exists yet. A call with an explicit + ``session``, ``region_name`` or ``config`` returns an instance built from exactly + those arguments, cached so repeated calls with the same objects are cheap. The + first instance ever created also becomes the default, so code that configures + ``SageMakerClient(session=...)`` once up front and then relies on bare + ``SageMakerClient()`` calls keeps working. + + The keyed entries form a small LRU: once ``_MAX_KEYED_ENTRIES`` distinct + argument sets have been seen, the least recently used one is dropped, so a + long-lived process that mints a fresh session per unit of work does not retain + every session and its four boto3 clients forever. The default entry is never + evicted. Construction is serialized by a lock so concurrent first callers for + the same key share one instance. + + This replaces a plain singleton, which returned whichever instance was created + first and silently ignored the session passed on every later call. + """ + + _DEFAULT_KEY = "default" + _MAX_KEYED_ENTRIES = 32 + _instances: Dict[type, "OrderedDict[Any, Any]"] = {} + _lock = threading.RLock() + + def __call__(cls, *args, **kwargs): + """Return a cached instance for these arguments, creating it if needed.""" + key = cls._cache_key(*args, **kwargs) + with cls._lock: + cache = cls._instances.setdefault(cls, OrderedDict()) + instance = cache.get(key) + if instance is not None: + if key != cls._DEFAULT_KEY: + cache.move_to_end(key) + return instance + instance = super().__call__(*args, **kwargs) + cache[key] = instance + # The first client created in the process becomes the default used by + # argument-less calls, matching the previous singleton behaviour. + cache.setdefault(cls._DEFAULT_KEY, instance) + _ClientCacheMeta._evict(cache, cls._DEFAULT_KEY, cls._MAX_KEYED_ENTRIES) + return instance + + @staticmethod + def _evict(cache, default_key, max_keyed_entries): + """Drop least recently used keyed entries beyond the cap; keep the default.""" + keyed = [k for k in cache if k != default_key] + for key in keyed[: max(0, len(keyed) - max_keyed_entries)]: + del cache[key] + + +class SageMakerClient(metaclass=_ClientCacheMeta): + """ + Cached factory for SageMaker boto3 clients. + + Clients are cached per (session, region_name, config). Passing an explicit boto3 + ``session`` always yields clients signed with that session's credentials, even if + a client for a different session was created earlier in the process. Calling + ``SageMakerClient()`` with no arguments returns the process default. """ + @classmethod + def _cache_key(cls, session: Session = None, region_name: str = None, config: Config = None): + """Build the cache key for a constructor call. + + Sessions and configs are keyed by identity: two distinct boto3 sessions must + never share a client even if they look alike, because credentials live on the + session object. The cached instance keeps references to both, so the ids + cannot be recycled while the entry is alive. + """ + if session is None and region_name is None and config is None: + return cls._DEFAULT_KEY + return ( + id(session) if session is not None else None, + region_name, + id(config) if config is not None else None, + ) + @classmethod def reset(cls): - """Reset the singleton instance.""" - SingletonMeta._instances.pop(cls, None) + """Drop every cached instance, including the default.""" + with _ClientCacheMeta._lock: + _ClientCacheMeta._instances.pop(cls, None) def __init__( self, @@ -365,13 +444,16 @@ def __init__( logger.debug("No config provided. Using default config.") config = Config(retries={"max_attempts": 10, "mode": "standard"}) - self.config = Config(user_agent_extra=get_user_agent_extra_suffix()) + # Keep the caller's config object alive: the cache key uses its identity. + self._base_config = config + user_agent_extra = get_user_agent_extra_suffix() + if config.user_agent_extra: + user_agent_extra = f"{config.user_agent_extra} {user_agent_extra}" + self.config = config.merge(Config(user_agent_extra=user_agent_extra)) self.session = session self.region_name = region_name - self.sagemaker_client = session.client( - "sagemaker", region_name, config=self.config - ) + self.sagemaker_client = session.client("sagemaker", region_name, config=self.config) self.sagemaker_runtime_client = session.client( "sagemaker-runtime", region_name, config=self.config ) diff --git a/sagemaker-core/tests/unit/test_sagemaker_client.py b/sagemaker-core/tests/unit/test_sagemaker_client.py new file mode 100644 index 0000000000..8e9f92c66b --- /dev/null +++ b/sagemaker-core/tests/unit/test_sagemaker_client.py @@ -0,0 +1,230 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. +"""Tests for SageMakerClient caching and session handling. + +Regression coverage for aws/sagemaker-python-sdk#5986 and #6069: a client built +for one boto3 session must never be handed to a caller that passed a different +session, and the ``config`` argument must actually reach the boto3 clients. +""" + +from __future__ import absolute_import + +import boto3 +import pytest +from botocore.config import Config + +from sagemaker.core.utils.utils import SageMakerClient + +REGION_A = "us-west-2" +REGION_B = "us-east-1" + + +def _session(access_key, region): + """Offline boto3 session carrying distinguishable static credentials.""" + return boto3.Session( + aws_access_key_id=access_key, + aws_secret_access_key="secret-" + access_key, + region_name=region, + ) + + +def _access_key(boto_client): + return boto_client._request_signer._credentials.access_key + + +@pytest.fixture(autouse=True) +def _isolated_cache(): + SageMakerClient.reset() + yield + SageMakerClient.reset() + + +def test_explicit_session_is_honored_after_another_client_exists(): + """The second session must not receive the first session's client (#5986, #6069).""" + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + session_b = _session("AKIASECONDSESSION000", REGION_B) + + client_a = SageMakerClient(session=session_a) + client_b = SageMakerClient(session=session_b) + + assert client_a is not client_b + assert client_b.session is session_b + assert client_b.region_name == REGION_B + for service in ( + "sagemaker", + "sagemaker-runtime", + "sagemaker-featurestore-runtime", + "sagemaker-metrics", + ): + assert _access_key(client_b.get_client(service)) == "AKIASECONDSESSION000" + assert _access_key(client_a.get_client(service)) == "AKIAFIRSTSESSION0000" + + +def test_same_session_returns_cached_instance(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + + assert SageMakerClient(session=session_a) is SageMakerClient(session=session_a) + assert SageMakerClient(session=session_a, region_name=REGION_A) is SageMakerClient( + session=session_a, region_name=REGION_A + ) + + +def test_same_session_different_region_gets_distinct_client(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + + client_a = SageMakerClient(session=session_a, region_name=REGION_A) + client_b = SageMakerClient(session=session_a, region_name=REGION_B) + + assert client_a is not client_b + assert client_b.sagemaker_client.meta.region_name == REGION_B + + +def test_bare_call_returns_first_created_instance_as_default(): + """Configure-once pattern: SageMakerClient(session=...) then bare SageMakerClient().""" + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + + configured = SageMakerClient(session=session_a) + + assert SageMakerClient() is configured + assert SageMakerClient() is configured + + +def test_bare_call_default_is_not_replaced_by_later_explicit_session(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + session_b = _session("AKIASECONDSESSION000", REGION_B) + + default = SageMakerClient(session=session_a) + SageMakerClient(session=session_b) + + assert SageMakerClient() is default + + +def test_bare_call_creates_default_from_default_chain(monkeypatch): + monkeypatch.setenv("AWS_ACCESS_KEY_ID", "AKIAENVIRONMENT00000") + monkeypatch.setenv("AWS_SECRET_ACCESS_KEY", "secret") + monkeypatch.setenv("AWS_DEFAULT_REGION", REGION_A) + + default = SageMakerClient() + + assert SageMakerClient() is default + assert default.region_name == REGION_A + assert _access_key(default.sagemaker_client) == "AKIAENVIRONMENT00000" + + +def test_config_argument_is_applied_and_user_agent_suffix_appended(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + config = Config(connect_timeout=3, read_timeout=7, user_agent_extra="mytool/1.0") + + client = SageMakerClient(session=session_a, config=config) + + meta_config = client.sagemaker_client.meta.config + assert meta_config.connect_timeout == 3 + assert meta_config.read_timeout == 7 + assert meta_config.user_agent_extra.startswith("mytool/1.0 ") + assert "sagemaker" in meta_config.user_agent_extra.lower() + + +def test_default_config_keeps_retry_settings(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + + client = SageMakerClient(session=session_a) + + # botocore normalizes {"max_attempts": N} to {"total_max_attempts": N + 1}. + retries = client.sagemaker_client.meta.config.retries + assert retries["total_max_attempts"] == 11 + assert retries["mode"] == "standard" + + +def test_distinct_config_objects_get_distinct_clients(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + config_1 = Config(connect_timeout=1) + config_2 = Config(connect_timeout=2) + + client_1 = SageMakerClient(session=session_a, config=config_1) + client_2 = SageMakerClient(session=session_a, config=config_2) + + assert client_1 is not client_2 + assert client_1.sagemaker_client.meta.config.connect_timeout == 1 + assert client_2.sagemaker_client.meta.config.connect_timeout == 2 + + +def test_reset_clears_default_and_keyed_entries(): + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + client_a = SageMakerClient(session=session_a) + default = SageMakerClient() + + SageMakerClient.reset() + + assert SageMakerClient(session=session_a) is not client_a + assert SageMakerClient() is not default + + +def _cached_entries(): + from sagemaker.core.utils.utils import _ClientCacheMeta + + return _ClientCacheMeta._instances.get(SageMakerClient, {}) + + +def test_keyed_cache_is_bounded_and_default_survives_eviction(): + from sagemaker.core.utils.utils import _ClientCacheMeta + + cap = _ClientCacheMeta._MAX_KEYED_ENTRIES + sessions = [_session(f"AKIA{i:016d}", REGION_A) for i in range(cap + 5)] + + default = SageMakerClient(session=sessions[0]) + clients = [SageMakerClient(session=s) for s in sessions] + + entries = _cached_entries() + keyed = [k for k in entries if k != _ClientCacheMeta._DEFAULT_KEY] + assert len(keyed) == cap + # The oldest keyed entries were dropped, the newest kept. + assert SageMakerClient(session=sessions[-1]) is clients[-1] + assert SageMakerClient(session=sessions[0]) is not clients[0] + # The process default is pinned regardless of eviction. + assert SageMakerClient() is default + + +def test_recently_used_entry_is_kept_over_stale_ones(): + from sagemaker.core.utils.utils import _ClientCacheMeta + + cap = _ClientCacheMeta._MAX_KEYED_ENTRIES + sessions = [_session(f"AKIA{i:016d}", REGION_A) for i in range(cap)] + clients = [SageMakerClient(session=s) for s in sessions] + + # Touch the oldest entry so it becomes most recently used, then overflow by one. + assert SageMakerClient(session=sessions[0]) is clients[0] + SageMakerClient(session=_session("AKIAOVERFLOW00000000", REGION_A)) + + assert SageMakerClient(session=sessions[0]) is clients[0] + assert SageMakerClient(session=sessions[1]) is not clients[1] + + +def test_concurrent_first_calls_share_one_instance(): + import threading + + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + results = [] + start = threading.Barrier(8) + + def build(): + start.wait() + results.append(SageMakerClient(session=session_a)) + + threads = [threading.Thread(target=build) for _ in range(8)] + for t in threads: + t.start() + for t in threads: + t.join() + + assert len(results) == 8 + assert all(r is results[0] for r in results) From 02af58bb69244ae55a9291514e8b64fc22a08c19 Mon Sep 17 00:00:00 2001 From: Amarjeet LNU Date: Fri, 25 Sep 2026 15:51:13 -0700 Subject: [PATCH 2/4] style(core): Start class docstring summaries on the first line pydocstyle D212 flagged the two class docstrings added by this change (_ClientCacheMeta, SageMakerClient) once #6294 made the sagemaker-core codestyle job enforceable. Docstring-only change. --- X-AI-Prompt: fix the failing sagemaker-core codestyle check on PR 6273 X-AI-Tool: Kiro --- sagemaker-core/src/sagemaker/core/utils/utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sagemaker-core/src/sagemaker/core/utils/utils.py b/sagemaker-core/src/sagemaker/core/utils/utils.py index f89780ef69..7f8687a42a 100644 --- a/sagemaker-core/src/sagemaker/core/utils/utils.py +++ b/sagemaker-core/src/sagemaker/core/utils/utils.py @@ -327,8 +327,7 @@ def __call__(cls, *args, **kwargs): class _ClientCacheMeta(type): - """ - Metaclass that caches instances per constructor arguments. + """Metaclass that caches instances per constructor arguments. A call with no arguments returns the process-wide default instance, creating it from the default credential chain if none exists yet. A call with an explicit @@ -381,8 +380,7 @@ def _evict(cache, default_key, max_keyed_entries): class SageMakerClient(metaclass=_ClientCacheMeta): - """ - Cached factory for SageMaker boto3 clients. + """Cached factory for SageMaker boto3 clients. Clients are cached per (session, region_name, config). Passing an explicit boto3 ``session`` always yields clients signed with that session's credentials, even if From 26ee8ff1ae5a6331e221ef116dbf35c5a283185c Mon Sep 17 00:00:00 2001 From: AMARJEET J Date: Thu, 1 Oct 2026 21:56:15 +0000 Subject: [PATCH 3/4] fix(core): Thread the resource session through object methods The previous commit made SageMakerClient honor an explicit session, but the generated object methods still ignored it: refresh(), update(), delete() and stop() called Base.get_sagemaker_client() (or a bare SageMakerClient()) with no session and fell back to the process default client. With a default-chain client built first, ModelTrainer.train(wait=True) created the job in the caller's account and then polled it in another one (#6069). Base now carries private _session/_region attributes. get() (and so create(), load(), and the get_all() iterator for each listed resource) binds them; refresh/update/delete/stop and every generated object method build their client from them, with explicit session/region arguments still taking precedence. Resources constructed directly keep the old process-default behaviour. Changes are made in the codegen templates and resources.py is regenerated from them; only the client-context hunks are kept, the unrelated service-model docstring drift from regeneration is dropped. Related: #6069 --- X-AI-Prompt: Fix the generated refresh/wait/stop methods to use the resource's session (PR 6273 review) X-AI-Tool: Kiro --- .../src/sagemaker/core/resources.py | 846 +++++++++++------- .../sagemaker/core/tools/resources_codegen.py | 38 +- .../src/sagemaker/core/tools/templates.py | 38 +- .../src/sagemaker/core/utils/utils.py | 16 +- .../unit/test_resource_client_context.py | 116 +++ 5 files changed, 702 insertions(+), 352 deletions(-) create mode 100644 sagemaker-core/tests/unit/test_resource_client_context.py diff --git a/sagemaker-core/src/sagemaker/core/resources.py b/sagemaker-core/src/sagemaker/core/resources.py index 398ea76fe2..19a314fc3f 100644 --- a/sagemaker-core/src/sagemaker/core/resources.py +++ b/sagemaker-core/src/sagemaker/core/resources.py @@ -14,7 +14,7 @@ import datetime import time import functools -from pydantic import validate_call +from pydantic import PrivateAttr, validate_call from typing import Dict, List, Literal, Optional, Union, Any from boto3.session import Session from rich.console import Group @@ -57,6 +57,11 @@ class Base(BaseModel): arbitrary_types_allowed=True, ) config_manager: ClassVar[SageMakerConfig] = SageMakerConfig() + # Session and region the resource was created or loaded with. Object methods + # (refresh, wait, update, delete, stop, ...) reuse them so a resource obtained + # with an explicit session keeps talking to the same account and region. + _session: Optional[Session] = PrivateAttr(default=None) + _region: Optional[str] = PrivateAttr(default=None) @classmethod def get_sagemaker_client(cls, session=None, region_name=None, service_name="sagemaker"): @@ -64,6 +69,23 @@ def get_sagemaker_client(cls, session=None, region_name=None, service_name="sage service_name=service_name ) + def _set_client_context(self, session: Optional[Session] = None, region: Optional[str] = None): + self._session = session + self._region = region + return self + + def _get_client( + self, + service_name: str = "sagemaker", + session: Optional[Session] = None, + region: Optional[str] = None, + ): + return Base.get_sagemaker_client( + session=session or self._session, + region_name=region or self._region, + service_name=service_name, + ) + @staticmethod def get_updated_kwargs_with_configured_attributes( config_schema_for_resource: dict, resource_name: str, **kwargs @@ -346,6 +368,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAIBenchmarkJobResponse") ai_benchmark_job = cls(**transformed_response) + ai_benchmark_job._set_client_context(session=session, region=region) return ai_benchmark_job @Base.add_validate_call @@ -378,7 +401,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_ai_benchmark_job(**operation_input_args) # deserialize response and update self @@ -405,7 +428,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "AIBenchmarkJobName": self.ai_benchmark_job_name, @@ -436,7 +459,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "AIBenchmarkJobName": self.ai_benchmark_job_name, @@ -574,6 +597,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_ai_benchmark_jobs", summaries_key="AIBenchmarkJobs", summary_name="AIBenchmarkJobSummary", @@ -798,6 +823,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAIRecommendationJobResponse") ai_recommendation_job = cls(**transformed_response) + ai_recommendation_job._set_client_context(session=session, region=region) return ai_recommendation_job @Base.add_validate_call @@ -830,7 +856,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_ai_recommendation_job(**operation_input_args) # deserialize response and update self @@ -857,7 +883,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "AIRecommendationJobName": self.ai_recommendation_job_name, @@ -888,7 +914,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "AIRecommendationJobName": self.ai_recommendation_job_name, @@ -1026,6 +1052,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_ai_recommendation_jobs", summaries_key="AIRecommendationJobs", summary_name="AIRecommendationJobSummary", @@ -1191,6 +1219,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAIWorkloadConfigResponse") ai_workload_config = cls(**transformed_response) + ai_workload_config._set_client_context(session=session, region=region) return ai_workload_config @Base.add_validate_call @@ -1223,7 +1252,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_ai_workload_config(**operation_input_args) # deserialize response and update self @@ -1251,7 +1280,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "AIWorkloadConfigName": self.ai_workload_config_name, @@ -1323,6 +1352,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_ai_workload_configs", summaries_key="AIWorkloadConfigs", summary_name="AIWorkloadConfigSummary", @@ -1511,6 +1542,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeActionResponse") action = cls(**transformed_response) + action._set_client_context(session=session, region=region) return action @Base.add_validate_call @@ -1543,7 +1575,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_action(**operation_input_args) # deserialize response and update self @@ -1582,7 +1614,7 @@ def update( """ logger.info("Updating action resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ActionName": self.action_name, @@ -1623,7 +1655,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ActionName": self.action_name, @@ -1699,6 +1731,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_actions", summaries_key="ActionSummaries", summary_name="ActionSummary", @@ -1900,6 +1934,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAlgorithmOutput") algorithm = cls(**transformed_response) + algorithm._set_client_context(session=session, region=region) return algorithm @Base.add_validate_call @@ -1931,7 +1966,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_algorithm(**operation_input_args) # deserialize response and update self @@ -1958,7 +1993,7 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "AlgorithmName": self.algorithm_name, @@ -2147,6 +2182,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_algorithms", summaries_key="AlgorithmSummaryList", summary_name="AlgorithmSummary", @@ -2358,6 +2395,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAppResponse") app = cls(**transformed_response) + app._set_client_context(session=session, region=region) return app @Base.add_validate_call @@ -2394,7 +2432,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_app(**operation_input_args) # deserialize response and update self @@ -2422,7 +2460,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -2619,6 +2657,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_apps", summaries_key="Apps", summary_name="AppDetails", @@ -2786,6 +2826,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAppImageConfigResponse") app_image_config = cls(**transformed_response) + app_image_config._set_client_context(session=session, region=region) return app_image_config @Base.add_validate_call @@ -2818,7 +2859,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_app_image_config(**operation_input_args) # deserialize response and update self @@ -2852,7 +2893,7 @@ def update( """ logger.info("Updating app_image_config resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "AppImageConfigName": self.app_image_config_name, @@ -2892,7 +2933,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "AppImageConfigName": self.app_image_config_name, @@ -2970,6 +3011,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_app_image_configs", summaries_key="AppImageConfigs", summary_name="AppImageConfigDetails", @@ -3148,6 +3191,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeArtifactResponse") artifact = cls(**transformed_response) + artifact._set_client_context(session=session, region=region) return artifact @Base.add_validate_call @@ -3180,7 +3224,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_artifact(**operation_input_args) # deserialize response and update self @@ -3218,7 +3262,7 @@ def update( """ logger.info("Updating artifact resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ArtifactArn": self.artifact_arn, @@ -3258,7 +3302,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ArtifactArn": self.artifact_arn, @@ -3335,6 +3379,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_artifacts", summaries_key="ArtifactSummaries", summary_name="ArtifactSummary", @@ -3406,7 +3452,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "SourceArn": self.source_arn, @@ -3492,6 +3538,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_associations", summaries_key="AssociationSummaries", summary_name="AssociationSummary", @@ -3786,6 +3834,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAutoMLJobResponse") auto_ml_job = cls(**transformed_response) + auto_ml_job._set_client_context(session=session, region=region) return auto_ml_job @Base.add_validate_call @@ -3818,7 +3867,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_auto_ml_job(**operation_input_args) # deserialize response and update self @@ -3843,7 +3892,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "AutoMLJobName": self.auto_ml_job_name, @@ -3987,6 +4036,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_auto_ml_jobs", summaries_key="AutoMLJobSummaries", summary_name="AutoMLJobSummary", @@ -4044,12 +4095,12 @@ def get_all_candidates( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_candidates_for_auto_ml_job", summaries_key="Candidates", summary_name="AutoMLCandidate", @@ -4304,6 +4355,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeAutoMLJobV2Response") auto_ml_job_v2 = cls(**transformed_response) + auto_ml_job_v2._set_client_context(session=session, region=region) return auto_ml_job_v2 @Base.add_validate_call @@ -4336,7 +4388,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_auto_ml_job_v2(**operation_input_args) # deserialize response and update self @@ -4630,6 +4682,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeClusterResponse") cluster = cls(**transformed_response) + cluster._set_client_context(session=session, region=region) return cluster @Base.add_validate_call @@ -4662,7 +4715,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_cluster(**operation_input_args) # deserialize response and update self @@ -4713,7 +4766,7 @@ def update( """ logger.info("Updating cluster resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ClusterName": self.cluster_name, @@ -4761,7 +4814,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ClusterName": self.cluster_name, @@ -4961,6 +5014,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_clusters", summaries_key="ClusterSummaries", summary_name="ClusterSummary", @@ -5010,9 +5065,7 @@ def get_node( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling describe_cluster_node API") response = client.describe_cluster_node(**operation_input_args) @@ -5077,12 +5130,12 @@ def get_all_nodes( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_cluster_nodes", summaries_key="ClusterNodeSummaries", summary_name="ClusterNodeSummary", @@ -5131,9 +5184,7 @@ def update_software( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling update_cluster_software API") response = client.update_cluster_software(**operation_input_args) @@ -5181,9 +5232,7 @@ def batch_delete_nodes( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling batch_delete_cluster_nodes API") response = client.batch_delete_cluster_nodes(**operation_input_args) @@ -5381,6 +5430,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeClusterSchedulerConfigResponse") cluster_scheduler_config = cls(**transformed_response) + cluster_scheduler_config._set_client_context(session=session, region=region) return cluster_scheduler_config @Base.add_validate_call @@ -5414,7 +5464,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_cluster_scheduler_config(**operation_input_args) # deserialize response and update self @@ -5453,7 +5503,7 @@ def update( """ logger.info("Updating cluster_scheduler_config resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ClusterSchedulerConfigId": self.cluster_scheduler_config_id, @@ -5493,7 +5543,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ClusterSchedulerConfigId": self.cluster_scheduler_config_id, @@ -5713,6 +5763,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_cluster_scheduler_configs", summaries_key="ClusterSchedulerConfigSummaries", summary_name="ClusterSchedulerConfigSummary", @@ -5868,6 +5920,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeCodeRepositoryOutput") code_repository = cls(**transformed_response) + code_repository._set_client_context(session=session, region=region) return code_repository @Base.add_validate_call @@ -5899,7 +5952,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_code_repository(**operation_input_args) # deserialize response and update self @@ -5931,7 +5984,7 @@ def update( """ logger.info("Updating code_repository resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "CodeRepositoryName": self.code_repository_name, @@ -5968,7 +6021,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "CodeRepositoryName": self.code_repository_name, @@ -6045,6 +6098,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_code_repositories", summaries_key="CodeRepositorySummaryList", summary_name="CodeRepositorySummary", @@ -6270,6 +6325,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeCompilationJobResponse") compilation_job = cls(**transformed_response) + compilation_job._set_client_context(session=session, region=region) return compilation_job @Base.add_validate_call @@ -6302,7 +6358,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_compilation_job(**operation_input_args) # deserialize response and update self @@ -6329,7 +6385,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "CompilationJobName": self.compilation_job_name, @@ -6360,7 +6416,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "CompilationJobName": self.compilation_job_name, @@ -6504,6 +6560,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_compilation_jobs", summaries_key="CompilationJobSummaries", summary_name="CompilationJobSummary", @@ -6697,6 +6755,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeComputeQuotaResponse") compute_quota = cls(**transformed_response) + compute_quota._set_client_context(session=session, region=region) return compute_quota @Base.add_validate_call @@ -6730,7 +6789,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_compute_quota(**operation_input_args) # deserialize response and update self @@ -6771,7 +6830,7 @@ def update( """ logger.info("Updating compute_quota resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ComputeQuotaId": self.compute_quota_id, @@ -6813,7 +6872,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ComputeQuotaId": self.compute_quota_id, @@ -7029,6 +7088,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_compute_quotas", summaries_key="ComputeQuotaSummaries", summary_name="ComputeQuotaSummary", @@ -7207,6 +7268,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeContextResponse") context = cls(**transformed_response) + context._set_client_context(session=session, region=region) return context @Base.add_validate_call @@ -7239,7 +7301,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_context(**operation_input_args) # deserialize response and update self @@ -7277,7 +7339,7 @@ def update( """ logger.info("Updating context resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ContextName": self.context_name, @@ -7317,7 +7379,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ContextName": self.context_name, @@ -7393,6 +7455,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_contexts", summaries_key="ContextSummaries", summary_name="ContextSummary", @@ -7623,6 +7687,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeDataQualityJobDefinitionResponse") data_quality_job_definition = cls(**transformed_response) + data_quality_job_definition._set_client_context(session=session, region=region) return data_quality_job_definition @Base.add_validate_call @@ -7655,7 +7720,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_data_quality_job_definition(**operation_input_args) # deserialize response and update self @@ -7682,7 +7747,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "JobDefinitionName": self.job_definition_name, @@ -7760,6 +7825,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_data_quality_job_definitions", summaries_key="JobDefinitionSummaries", summary_name="MonitoringJobDefinitionSummary", @@ -7871,6 +7938,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeDeviceResponse") device = cls(**transformed_response) + device._set_client_context(session=session, region=region) return device @Base.add_validate_call @@ -7905,7 +7973,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_device(**operation_input_args) # deserialize response and update self @@ -7965,6 +8033,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_devices", summaries_key="DeviceSummaries", summary_name="DeviceSummary", @@ -8159,6 +8229,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeDeviceFleetResponse") device_fleet = cls(**transformed_response) + device_fleet._set_client_context(session=session, region=region) return device_fleet @Base.add_validate_call @@ -8191,7 +8262,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_device_fleet(**operation_input_args) # deserialize response and update self @@ -8230,7 +8301,7 @@ def update( """ logger.info("Updating device_fleet resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DeviceFleetName": self.device_fleet_name, @@ -8271,7 +8342,7 @@ def delete( ResourceInUse: Resource being accessed is in use. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DeviceFleetName": self.device_fleet_name, @@ -8349,6 +8420,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_device_fleets", summaries_key="DeviceFleetSummaries", summary_name="DeviceFleetSummary", @@ -8391,9 +8464,7 @@ def deregister_devices( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling deregister_devices API") response = client.deregister_devices(**operation_input_args) @@ -8434,9 +8505,7 @@ def get_report( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling get_device_fleet_report API") response = client.get_device_fleet_report(**operation_input_args) @@ -8484,9 +8553,7 @@ def register_devices( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling register_devices API") response = client.register_devices(**operation_input_args) @@ -8527,9 +8594,7 @@ def update_devices( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling update_devices API") response = client.update_devices(**operation_input_args) @@ -8826,6 +8891,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeDomainResponse") domain = cls(**transformed_response) + domain._set_client_context(session=session, region=region) return domain @Base.add_validate_call @@ -8858,7 +8924,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_domain(**operation_input_args) # deserialize response and update self @@ -8904,7 +8970,7 @@ def update( """ logger.info("Updating domain resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -8952,7 +9018,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -9123,6 +9189,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_domains", summaries_key="Domains", summary_name="DomainDetails", @@ -9305,6 +9373,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeEdgeDeploymentPlanResponse") edge_deployment_plan = cls(**transformed_response) + edge_deployment_plan._set_client_context(session=session, region=region) return edge_deployment_plan @Base.add_validate_call @@ -9340,7 +9409,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_edge_deployment_plan(**operation_input_args) # deserialize response and update self @@ -9367,7 +9436,7 @@ def delete( ResourceInUse: Resource being accessed is in use. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "EdgeDeploymentPlanName": self.edge_deployment_plan_name, @@ -9448,6 +9517,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_edge_deployment_plans", summaries_key="EdgeDeploymentPlanSummaries", summary_name="EdgeDeploymentPlanSummary", @@ -9489,9 +9560,7 @@ def create_stage( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling create_edge_deployment_stage API") response = client.create_edge_deployment_stage(**operation_input_args) @@ -9533,9 +9602,7 @@ def delete_stage( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling delete_edge_deployment_stage API") response = client.delete_edge_deployment_stage(**operation_input_args) @@ -9576,9 +9643,7 @@ def start_stage( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling start_edge_deployment_stage API") response = client.start_edge_deployment_stage(**operation_input_args) @@ -9619,9 +9684,7 @@ def stop_stage( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling stop_edge_deployment_stage API") response = client.stop_edge_deployment_stage(**operation_input_args) @@ -9669,12 +9732,12 @@ def get_all_stage_devices( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_stage_devices", summaries_key="DeviceDeploymentSummaries", summary_name="DeviceDeploymentSummary", @@ -9889,6 +9952,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeEdgePackagingJobResponse") edge_packaging_job = cls(**transformed_response) + edge_packaging_job._set_client_context(session=session, region=region) return edge_packaging_job @Base.add_validate_call @@ -9921,7 +9985,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_edge_packaging_job(**operation_input_args) # deserialize response and update self @@ -9945,7 +10009,7 @@ def stop(self) -> None: ``` """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "EdgePackagingJobName": self.edge_packaging_job_name, @@ -10092,6 +10156,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_edge_packaging_jobs", summaries_key="EdgePackagingJobSummaries", summary_name="EdgePackagingJobSummary", @@ -10299,6 +10365,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeEndpointOutput") endpoint = cls(**transformed_response) + endpoint._set_client_context(session=session, region=region) return endpoint @Base.add_validate_call @@ -10330,7 +10397,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_endpoint(**operation_input_args) # deserialize response and update self @@ -10372,7 +10439,7 @@ def update( """ logger.info("Updating endpoint resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "EndpointName": self.endpoint_name, @@ -10413,7 +10480,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "EndpointName": self.endpoint_name, @@ -10621,6 +10688,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_endpoints", summaries_key="Endpoints", summary_name="EndpointSummary", @@ -10664,9 +10733,7 @@ def update_weights_and_capacities( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling update_endpoint_weights_and_capacities API") response = client.update_endpoint_weights_and_capacities(**operation_input_args) @@ -10757,9 +10824,7 @@ def invoke( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-runtime" - ) + client = self._get_client(service_name="sagemaker-runtime", session=session, region=region) logger.debug(f"Calling invoke_endpoint API") response = client.invoke_endpoint(**operation_input_args) @@ -10834,9 +10899,7 @@ def invoke_async( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-runtime" - ) + client = self._get_client(service_name="sagemaker-runtime", session=session, region=region) logger.debug(f"Calling invoke_endpoint_async API") response = client.invoke_endpoint_async(**operation_input_args) @@ -10913,9 +10976,7 @@ def invoke_with_response_stream( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-runtime" - ) + client = self._get_client(service_name="sagemaker-runtime", session=session, region=region) logger.debug(f"Calling invoke_endpoint_with_response_stream API") response = client.invoke_endpoint_with_response_stream(**operation_input_args) @@ -11148,6 +11209,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeEndpointConfigOutput") endpoint_config = cls(**transformed_response) + endpoint_config._set_client_context(session=session, region=region) return endpoint_config @Base.add_validate_call @@ -11179,7 +11241,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_endpoint_config(**operation_input_args) # deserialize response and update self @@ -11205,7 +11267,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "EndpointConfigName": self.endpoint_config_name, @@ -11277,6 +11339,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_endpoint_configs", summaries_key="EndpointConfigs", summary_name="EndpointConfigSummary", @@ -11445,6 +11509,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeExperimentResponse") experiment = cls(**transformed_response) + experiment._set_client_context(session=session, region=region) return experiment @Base.add_validate_call @@ -11477,7 +11542,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_experiment(**operation_input_args) # deserialize response and update self @@ -11511,7 +11576,7 @@ def update( """ logger.info("Updating experiment resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ExperimentName": self.experiment_name, @@ -11550,7 +11615,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ExperimentName": self.experiment_name, @@ -11619,6 +11684,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_experiments", summaries_key="ExperimentSummaries", summary_name="ExperimentSummary", @@ -11851,6 +11918,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeFeatureGroupResponse") feature_group = cls(**transformed_response) + feature_group._set_client_context(session=session, region=region) return feature_group @Base.add_validate_call @@ -11884,7 +11952,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_feature_group(**operation_input_args) # deserialize response and update self @@ -11923,7 +11991,7 @@ def update( """ logger.info("Updating feature_group resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "FeatureGroupName": self.feature_group_name, @@ -11963,7 +12031,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "FeatureGroupName": self.feature_group_name, @@ -12162,6 +12230,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_feature_groups", summaries_key="FeatureGroupSummaries", summary_name="FeatureGroupSummary", @@ -12218,8 +12288,8 @@ def get_record( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling get_record API") @@ -12274,8 +12344,8 @@ def put_record( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling put_record API") @@ -12332,8 +12402,8 @@ def update_record( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling update_record API") @@ -12388,8 +12458,8 @@ def delete_record( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling delete_record API") @@ -12440,8 +12510,8 @@ def batch_get_record( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling batch_get_record API") @@ -12496,8 +12566,8 @@ def batch_write_record( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling batch_write_record API") @@ -12556,8 +12626,8 @@ def list_records( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-featurestore-runtime" + client = self._get_client( + service_name="sagemaker-featurestore-runtime", session=session, region=region ) logger.debug(f"Calling list_records API") @@ -12661,6 +12731,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeFeatureMetadataResponse") feature_metadata = cls(**transformed_response) + feature_metadata._set_client_context(session=session, region=region) return feature_metadata @Base.add_validate_call @@ -12694,7 +12765,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_feature_metadata(**operation_input_args) # deserialize response and update self @@ -12732,7 +12803,7 @@ def update( """ logger.info("Updating feature_metadata resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "FeatureGroupName": self.feature_group_name, @@ -12946,6 +13017,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeFlowDefinitionResponse") flow_definition = cls(**transformed_response) + flow_definition._set_client_context(session=session, region=region) return flow_definition @Base.add_validate_call @@ -12978,7 +13050,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_flow_definition(**operation_input_args) # deserialize response and update self @@ -13006,7 +13078,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "FlowDefinitionName": self.flow_definition_name, @@ -13195,6 +13267,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_flow_definitions", summaries_key="FlowDefinitionSummaries", summary_name="FlowDefinitionSummary", @@ -13388,6 +13462,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeHubResponse") hub = cls(**transformed_response) + hub._set_client_context(session=session, region=region) return hub @Base.add_validate_call @@ -13420,7 +13495,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_hub(**operation_input_args) # deserialize response and update self @@ -13455,7 +13530,7 @@ def update( """ logger.info("Updating hub resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HubName": self.hub_name, @@ -13496,7 +13571,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HubName": self.hub_name, @@ -13699,6 +13774,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_hubs", summaries_key="HubSummaries", summary_name="HubInfo", @@ -13831,6 +13908,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeHubContentResponse") hub_content = cls(**transformed_response) + hub_content._set_client_context(session=session, region=region) return hub_content @Base.add_validate_call @@ -13866,7 +13944,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_hub_content(**operation_input_args) # deserialize response and update self @@ -13905,7 +13983,7 @@ def update( """ logger.info("Updating hub_content resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HubName": self.hub_name, @@ -13951,7 +14029,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HubName": self.hub_name, @@ -14169,12 +14247,12 @@ def get_all_versions( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_hub_content_versions", summaries_key="HubContentSummaries", summary_name="HubContentInfo", @@ -14431,7 +14509,7 @@ def update( """ logger.info("Updating hub_content_reference resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HubName": self.hub_name, @@ -14472,7 +14550,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HubName": self.hub_name, @@ -14638,6 +14716,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeHumanTaskUiResponse") human_task_ui = cls(**transformed_response) + human_task_ui._set_client_context(session=session, region=region) return human_task_ui @Base.add_validate_call @@ -14670,7 +14749,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_human_task_ui(**operation_input_args) # deserialize response and update self @@ -14697,7 +14776,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HumanTaskUiName": self.human_task_ui_name, @@ -14877,6 +14956,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_human_task_uis", summaries_key="HumanTaskUiSummaries", summary_name="HumanTaskUiSummary", @@ -15110,6 +15191,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeHyperParameterTuningJobResponse") hyper_parameter_tuning_job = cls(**transformed_response) + hyper_parameter_tuning_job._set_client_context(session=session, region=region) return hyper_parameter_tuning_job @Base.add_validate_call @@ -15142,7 +15224,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_hyper_parameter_tuning_job(**operation_input_args) # deserialize response and update self @@ -15168,7 +15250,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "HyperParameterTuningJobName": self.hyper_parameter_tuning_job_name, @@ -15199,7 +15281,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "HyperParameterTuningJobName": self.hyper_parameter_tuning_job_name, @@ -15406,6 +15488,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_hyper_parameter_tuning_jobs", summaries_key="HyperParameterTuningJobSummaries", summary_name="HyperParameterTuningJobSummary", @@ -15460,12 +15544,12 @@ def get_all_training_jobs( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_training_jobs_for_hyper_parameter_tuning_job", summaries_key="TrainingJobSummaries", summary_name="HyperParameterTrainingJobSummary", @@ -15652,6 +15736,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeImageResponse") image = cls(**transformed_response) + image._set_client_context(session=session, region=region) return image @Base.add_validate_call @@ -15684,7 +15769,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_image(**operation_input_args) # deserialize response and update self @@ -15724,7 +15809,7 @@ def update( """ logger.info("Updating image resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DeleteProperties": delete_properties, @@ -15766,7 +15851,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ImageName": self.image_name, @@ -15977,6 +16062,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_images", summaries_key="Images", summary_name="Image", @@ -16028,12 +16115,12 @@ def get_all_aliases( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_aliases", summaries_key="SageMakerImageVersionAliases", summary_name="SageMakerImageVersionAlias", @@ -16246,6 +16333,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeImageVersionResponse") image_version = cls(**transformed_response) + image_version._set_client_context(session=session, region=region) return image_version @Base.add_validate_call @@ -16281,7 +16369,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_image_version(**operation_input_args) # deserialize response and update self @@ -16329,7 +16417,7 @@ def update( """ logger.info("Updating image_version resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ImageName": self.image_name, @@ -16379,7 +16467,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ImageName": self.image_name, @@ -16702,6 +16790,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeInferenceComponentOutput") inference_component = cls(**transformed_response) + inference_component._set_client_context(session=session, region=region) return inference_component @Base.add_validate_call @@ -16733,7 +16822,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_inference_component(**operation_input_args) # deserialize response and update self @@ -16771,7 +16860,7 @@ def update( """ logger.info("Updating inference_component resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "InferenceComponentName": self.inference_component_name, @@ -16811,7 +16900,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "InferenceComponentName": self.inference_component_name, @@ -17023,6 +17112,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_inference_components", summaries_key="InferenceComponents", summary_name="InferenceComponentSummary", @@ -17066,9 +17157,7 @@ def update_runtime_configs( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling update_inference_component_runtime_config API") response = client.update_inference_component_runtime_config(**operation_input_args) @@ -17289,6 +17378,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeInferenceExperimentResponse") inference_experiment = cls(**transformed_response) + inference_experiment._set_client_context(session=session, region=region) return inference_experiment @Base.add_validate_call @@ -17321,7 +17411,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_inference_experiment(**operation_input_args) # deserialize response and update self @@ -17359,7 +17449,7 @@ def update( """ logger.info("Updating inference_experiment resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "Name": self.name, @@ -17402,7 +17492,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "Name": self.name, @@ -17449,9 +17539,7 @@ def start( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling start_inference_experiment API") response = client.start_inference_experiment(**operation_input_args) @@ -17476,7 +17564,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "Name": self.name, @@ -17628,6 +17716,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_inference_experiments", summaries_key="InferenceExperiments", summary_name="InferenceExperimentSummary", @@ -17842,6 +17932,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeInferenceRecommendationsJobResponse") inference_recommendations_job = cls(**transformed_response) + inference_recommendations_job._set_client_context(session=session, region=region) return inference_recommendations_job @Base.add_validate_call @@ -17874,7 +17965,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_inference_recommendations_job(**operation_input_args) # deserialize response and update self @@ -17899,7 +17990,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "JobName": self.job_name, @@ -18116,6 +18207,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_inference_recommendations_jobs", summaries_key="InferenceRecommendationsJobs", summary_name="InferenceRecommendationsJob", @@ -18165,12 +18258,12 @@ def get_all_steps( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_inference_recommendations_job_steps", summaries_key="Steps", summary_name="InferenceRecommendationsJobStep", @@ -18374,6 +18467,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeJobResponse") job = cls(**transformed_response) + job._set_client_context(session=session, region=region) return job @Base.add_validate_call @@ -18407,7 +18501,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_job(**operation_input_args) # deserialize response and update self @@ -18435,7 +18529,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "JobName": self.job_name, @@ -18467,7 +18561,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "JobName": self.job_name, @@ -18674,6 +18768,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_jobs", summaries_key="JobSummaries", summary_name="JobSummary", @@ -18914,6 +19010,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeLabelingJobResponse") labeling_job = cls(**transformed_response) + labeling_job._set_client_context(session=session, region=region) return labeling_job @Base.add_validate_call @@ -18946,7 +19043,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_labeling_job(**operation_input_args) # deserialize response and update self @@ -18971,7 +19068,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "LabelingJobName": self.labeling_job_name, @@ -19115,6 +19212,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_labeling_jobs", summaries_key="LabelingJobSummaryList", summary_name="LabelingJobSummary", @@ -19213,6 +19312,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeLineageGroupResponse") lineage_group = cls(**transformed_response) + lineage_group._set_client_context(session=session, region=region) return lineage_group @Base.add_validate_call @@ -19245,7 +19345,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_lineage_group(**operation_input_args) # deserialize response and update self @@ -19308,6 +19408,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_lineage_groups", summaries_key="LineageGroupSummaries", summary_name="LineageGroupSummary", @@ -19351,9 +19453,7 @@ def get_policy( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling get_lineage_group_policy API") response = client.get_lineage_group_policy(**operation_input_args) @@ -19561,6 +19661,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeMlflowAppResponse") mlflow_app = cls(**transformed_response) + mlflow_app._set_client_context(session=session, region=region) return mlflow_app @Base.add_validate_call @@ -19593,7 +19694,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_mlflow_app(**operation_input_args) # deserialize response and update self @@ -19632,7 +19733,7 @@ def update( """ logger.info("Updating mlflow_app resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "Arn": self.arn, @@ -19675,7 +19776,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "Arn": self.arn, @@ -19887,6 +19988,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_mlflow_apps", summaries_key="Summaries", summary_name="MlflowAppSummary", @@ -20109,6 +20212,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeMlflowTrackingServerResponse") mlflow_tracking_server = cls(**transformed_response) + mlflow_tracking_server._set_client_context(session=session, region=region) return mlflow_tracking_server @Base.add_validate_call @@ -20141,7 +20245,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_mlflow_tracking_server(**operation_input_args) # deserialize response and update self @@ -20181,7 +20285,7 @@ def update( """ logger.info("Updating mlflow_tracking_server resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrackingServerName": self.tracking_server_name, @@ -20224,7 +20328,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrackingServerName": self.tracking_server_name, @@ -20271,9 +20375,7 @@ def start( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling start_mlflow_tracking_server API") response = client.start_mlflow_tracking_server(**operation_input_args) @@ -20298,7 +20400,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "TrackingServerName": self.tracking_server_name, @@ -20516,6 +20618,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_mlflow_tracking_servers", summaries_key="TrackingServerSummaries", summary_name="TrackingServerSummary", @@ -20726,6 +20830,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelOutput") model = cls(**transformed_response) + model._set_client_context(session=session, region=region) return model @Base.add_validate_call @@ -20757,7 +20862,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model(**operation_input_args) # deserialize response and update self @@ -20783,7 +20888,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ModelName": self.model_name, @@ -20855,6 +20960,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_models", summaries_key="Models", summary_name="ModelSummary", @@ -20901,12 +21008,12 @@ def get_all_metadata( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_model_metadata", summaries_key="ModelMetadataSummaries", summary_name="ModelMetadataSummary", @@ -21137,6 +21244,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelBiasJobDefinitionResponse") model_bias_job_definition = cls(**transformed_response) + model_bias_job_definition._set_client_context(session=session, region=region) return model_bias_job_definition @Base.add_validate_call @@ -21169,7 +21277,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_bias_job_definition(**operation_input_args) # deserialize response and update self @@ -21196,7 +21304,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "JobDefinitionName": self.job_definition_name, @@ -21274,6 +21382,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_bias_job_definitions", summaries_key="JobDefinitionSummaries", summary_name="MonitoringJobDefinitionSummary", @@ -21468,6 +21578,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelCardResponse") model_card = cls(**transformed_response) + model_card._set_client_context(session=session, region=region) return model_card @Base.add_validate_call @@ -21501,7 +21612,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_card(**operation_input_args) # deserialize response and update self @@ -21537,7 +21648,7 @@ def update( """ logger.info("Updating model_card resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ModelCardName": self.model_card_name, @@ -21577,7 +21688,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ModelCardName": self.model_card_name, @@ -21703,6 +21814,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_cards", summaries_key="ModelCardSummaries", summary_name="ModelCardSummary", @@ -21761,12 +21874,12 @@ def get_all_versions( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_model_card_versions", summaries_key="ModelCardVersionSummaryList", summary_name="ModelCardVersionSummary", @@ -21960,6 +22073,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelCardExportJobResponse") model_card_export_job = cls(**transformed_response) + model_card_export_job._set_client_context(session=session, region=region) return model_card_export_job @Base.add_validate_call @@ -21992,7 +22106,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_card_export_job(**operation_input_args) # deserialize response and update self @@ -22130,6 +22244,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_card_export_jobs", summaries_key="ModelCardExportJobSummaries", summary_name="ModelCardExportJobSummary", @@ -22366,6 +22482,7 @@ def get( response, "DescribeModelExplainabilityJobDefinitionResponse" ) model_explainability_job_definition = cls(**transformed_response) + model_explainability_job_definition._set_client_context(session=session, region=region) return model_explainability_job_definition @Base.add_validate_call @@ -22398,7 +22515,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_explainability_job_definition(**operation_input_args) # deserialize response and update self @@ -22425,7 +22542,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "JobDefinitionName": self.job_definition_name, @@ -22503,6 +22620,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_explainability_job_definitions", summaries_key="JobDefinitionSummaries", summary_name="MonitoringJobDefinitionSummary", @@ -22839,6 +22958,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelPackageOutput") model_package = cls(**transformed_response) + model_package._set_client_context(session=session, region=region) return model_package @Base.add_validate_call @@ -22870,7 +22990,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_package(**operation_input_args) # deserialize response and update self @@ -22920,7 +23040,7 @@ def update( """ logger.info("Updating model_package resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ModelPackageArn": self.model_package_arn, @@ -22968,7 +23088,7 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ModelPackageName": self.model_package_name, @@ -23168,6 +23288,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_packages", summaries_key="ModelPackageSummaryList", summary_name="ModelPackageSummary", @@ -23212,9 +23334,7 @@ def batch_get( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling batch_describe_model_package API") response = client.batch_describe_model_package(**operation_input_args) @@ -23381,6 +23501,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelPackageGroupOutput") model_package_group = cls(**transformed_response) + model_package_group._set_client_context(session=session, region=region) return model_package_group @Base.add_validate_call @@ -23412,7 +23533,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_package_group(**operation_input_args) # deserialize response and update self @@ -23439,7 +23560,7 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ModelPackageGroupName": self.model_package_group_name, @@ -23637,6 +23758,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_package_groups", summaries_key="ModelPackageGroupSummaryList", summary_name="ModelPackageGroupSummary", @@ -23679,9 +23802,7 @@ def get_policy( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling get_model_package_group_policy API") response = client.get_model_package_group_policy(**operation_input_args) @@ -23721,9 +23842,7 @@ def delete_policy( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling delete_model_package_group_policy API") response = client.delete_model_package_group_policy(**operation_input_args) @@ -23765,9 +23884,7 @@ def put_policy( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling put_model_package_group_policy API") response = client.put_model_package_group_policy(**operation_input_args) @@ -23996,6 +24113,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeModelQualityJobDefinitionResponse") model_quality_job_definition = cls(**transformed_response) + model_quality_job_definition._set_client_context(session=session, region=region) return model_quality_job_definition @Base.add_validate_call @@ -24028,7 +24146,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_model_quality_job_definition(**operation_input_args) # deserialize response and update self @@ -24055,7 +24173,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "JobDefinitionName": self.job_definition_name, @@ -24133,6 +24251,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_model_quality_job_definitions", summaries_key="JobDefinitionSummaries", summary_name="MonitoringJobDefinitionSummary", @@ -24212,7 +24332,7 @@ def update( """ logger.info("Updating monitoring_alert resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "MonitoringScheduleName": monitoring_schedule_name, @@ -24280,6 +24400,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_monitoring_alerts", summaries_key="MonitoringAlertSummaries", summary_name="MonitoringAlertSummary", @@ -24347,9 +24469,7 @@ def list_history( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling list_monitoring_alert_history API") response = client.list_monitoring_alert_history(**operation_input_args) @@ -24487,6 +24607,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_monitoring_executions", summaries_key="MonitoringExecutionSummaries", summary_name="MonitoringExecutionSummary", @@ -24694,6 +24816,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeMonitoringScheduleResponse") monitoring_schedule = cls(**transformed_response) + monitoring_schedule._set_client_context(session=session, region=region) return monitoring_schedule @Base.add_validate_call @@ -24726,7 +24849,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_monitoring_schedule(**operation_input_args) # deserialize response and update self @@ -24760,7 +24883,7 @@ def update( """ logger.info("Updating monitoring_schedule resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "MonitoringScheduleName": self.monitoring_schedule_name, @@ -24798,7 +24921,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "MonitoringScheduleName": self.monitoring_schedule_name, @@ -24844,9 +24967,7 @@ def start( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling start_monitoring_schedule API") response = client.start_monitoring_schedule(**operation_input_args) @@ -24870,7 +24991,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "MonitoringScheduleName": self.monitoring_schedule_name, @@ -25022,6 +25143,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_monitoring_schedules", summaries_key="MonitoringScheduleSummaries", summary_name="MonitoringScheduleSummary", @@ -25281,6 +25404,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeNotebookInstanceOutput") notebook_instance = cls(**transformed_response) + notebook_instance._set_client_context(session=session, region=region) return notebook_instance @Base.add_validate_call @@ -25312,7 +25436,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_notebook_instance(**operation_input_args) # deserialize response and update self @@ -25368,7 +25492,7 @@ def update( """ logger.info("Updating notebook_instance resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "NotebookInstanceName": self.notebook_instance_name, @@ -25419,7 +25543,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "NotebookInstanceName": self.notebook_instance_name, @@ -25465,9 +25589,7 @@ def start( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling start_notebook_instance API") response = client.start_notebook_instance(**operation_input_args) @@ -25490,7 +25612,7 @@ def stop(self) -> None: ``` """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "NotebookInstanceName": self.notebook_instance_name, @@ -25705,6 +25827,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_notebook_instances", summaries_key="NotebookInstances", summary_name="NotebookInstanceSummary", @@ -25871,6 +25995,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeNotebookInstanceLifecycleConfigOutput") notebook_instance_lifecycle_config = cls(**transformed_response) + notebook_instance_lifecycle_config._set_client_context(session=session, region=region) return notebook_instance_lifecycle_config @Base.add_validate_call @@ -25902,7 +26027,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_notebook_instance_lifecycle_config(**operation_input_args) # deserialize response and update self @@ -25935,7 +26060,7 @@ def update( """ logger.info("Updating notebook_instance_lifecycle_config resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "NotebookInstanceLifecycleConfigName": self.notebook_instance_lifecycle_config_name, @@ -25973,7 +26098,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "NotebookInstanceLifecycleConfigName": self.notebook_instance_lifecycle_config_name, @@ -26051,6 +26176,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_notebook_instance_lifecycle_configs", summaries_key="NotebookInstanceLifecycleConfigs", summary_name="NotebookInstanceLifecycleConfigSummary", @@ -26284,6 +26411,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeOptimizationJobResponse") optimization_job = cls(**transformed_response) + optimization_job._set_client_context(session=session, region=region) return optimization_job @Base.add_validate_call @@ -26316,7 +26444,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_optimization_job(**operation_input_args) # deserialize response and update self @@ -26343,7 +26471,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "OptimizationJobName": self.optimization_job_name, @@ -26374,7 +26502,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "OptimizationJobName": self.optimization_job_name, @@ -26521,6 +26649,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_optimization_jobs", summaries_key="OptimizationJobSummaries", summary_name="OptimizationJobSummary", @@ -26754,6 +26884,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribePartnerAppResponse") partner_app = cls(**transformed_response) + partner_app._set_client_context(session=session, region=region) return partner_app @Base.add_validate_call @@ -26788,7 +26919,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_partner_app(**operation_input_args) # deserialize response and update self @@ -26834,7 +26965,7 @@ def update( """ logger.info("Updating partner_app resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "Arn": self.arn, @@ -26881,7 +27012,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "Arn": self.arn, @@ -27044,6 +27175,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_partner_apps", summaries_key="Summaries", summary_name="PartnerAppSummary", @@ -27350,6 +27483,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribePipelineResponse") pipeline = cls(**transformed_response) + pipeline._set_client_context(session=session, region=region) return pipeline @Base.add_validate_call @@ -27384,7 +27518,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_pipeline(**operation_input_args) # deserialize response and update self @@ -27426,7 +27560,7 @@ def update( """ logger.info("Updating pipeline resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "PipelineName": self.pipeline_name, @@ -27471,7 +27605,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "PipelineName": self.pipeline_name, @@ -27656,6 +27790,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_pipelines", summaries_key="PipelineSummaries", summary_name="PipelineSummary", @@ -27768,6 +27904,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribePipelineExecutionResponse") pipeline_execution = cls(**transformed_response) + pipeline_execution._set_client_context(session=session, region=region) return pipeline_execution @Base.add_validate_call @@ -27800,7 +27937,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_pipeline_execution(**operation_input_args) # deserialize response and update self @@ -27835,7 +27972,7 @@ def update( """ logger.info("Updating pipeline_execution resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "PipelineExecutionArn": self.pipeline_execution_arn, @@ -27902,9 +28039,7 @@ def start( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling start_pipeline_execution API") response = client.start_pipeline_execution(**operation_input_args) @@ -27929,7 +28064,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "PipelineExecutionArn": self.pipeline_execution_arn, @@ -28063,6 +28198,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_pipeline_executions", summaries_key="PipelineExecutionSummaries", summary_name="PipelineExecutionSummary", @@ -28106,9 +28243,7 @@ def get_pipeline_definition( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling describe_pipeline_definition_for_execution API") response = client.describe_pipeline_definition_for_execution(**operation_input_args) @@ -28158,12 +28293,12 @@ def get_all_steps( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_pipeline_execution_steps", summaries_key="PipelineExecutionSteps", summary_name="PipelineExecutionStep", @@ -28209,12 +28344,12 @@ def get_all_parameters( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_pipeline_parameters_for_execution", summaries_key="PipelineParameters", summary_name="Parameter", @@ -28261,9 +28396,7 @@ def retry( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling retry_pipeline_execution API") response = client.retry_pipeline_execution(**operation_input_args) @@ -28310,9 +28443,7 @@ def send_execution_step_failure( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling send_pipeline_execution_step_failure API") response = client.send_pipeline_execution_step_failure(**operation_input_args) @@ -28361,9 +28492,7 @@ def send_execution_step_success( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling send_pipeline_execution_step_success API") response = client.send_pipeline_execution_step_success(**operation_input_args) @@ -28984,6 +29113,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeProcessingJobResponse") processing_job = cls(**transformed_response) + processing_job._set_client_context(session=session, region=region) return processing_job @Base.add_validate_call @@ -29016,7 +29146,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_processing_job(**operation_input_args) # deserialize response and update self @@ -29044,7 +29174,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ProcessingJobName": self.processing_job_name, @@ -29075,7 +29205,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "ProcessingJobName": self.processing_job_name, @@ -29241,6 +29371,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_processing_jobs", summaries_key="ProcessingJobSummaries", summary_name="ProcessingJobSummary", @@ -29421,6 +29553,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeProjectOutput") project = cls(**transformed_response) + project._set_client_context(session=session, region=region) return project @Base.add_validate_call @@ -29452,7 +29585,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_project(**operation_input_args) # deserialize response and update self @@ -29494,7 +29627,7 @@ def update( """ logger.info("Updating project resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ProjectName": self.project_name, @@ -29535,7 +29668,7 @@ def delete( ConflictException: There was a conflict when you attempted to modify a SageMaker entity such as an Experiment or Artifact. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "ProjectName": self.project_name, @@ -29674,6 +29807,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_projects", summaries_key="ProjectSummaryList", summary_name="ProjectSummary", @@ -29774,6 +29909,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_resource_catalogs", summaries_key="ResourceCatalogs", summary_name="ResourceCatalog", @@ -30074,6 +30211,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeSpaceResponse") space = cls(**transformed_response) + space._set_client_context(session=session, region=region) return space @Base.add_validate_call @@ -30107,7 +30245,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_space(**operation_input_args) # deserialize response and update self @@ -30142,7 +30280,7 @@ def update( """ logger.info("Updating space resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -30183,7 +30321,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -30386,6 +30524,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_spaces", summaries_key="Spaces", summary_name="SpaceDetails", @@ -30552,6 +30692,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeStudioLifecycleConfigResponse") studio_lifecycle_config = cls(**transformed_response) + studio_lifecycle_config._set_client_context(session=session, region=region) return studio_lifecycle_config @Base.add_validate_call @@ -30584,7 +30725,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_studio_lifecycle_config(**operation_input_args) # deserialize response and update self @@ -30612,7 +30753,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "StudioLifecycleConfigName": self.studio_lifecycle_config_name, @@ -30694,6 +30835,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_studio_lifecycle_configs", summaries_key="StudioLifecycleConfigs", summary_name="StudioLifecycleConfigDetails", @@ -30778,6 +30921,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeSubscribedWorkteamResponse") subscribed_workteam = cls(**transformed_response) + subscribed_workteam._set_client_context(session=session, region=region) return subscribed_workteam @Base.add_validate_call @@ -30809,7 +30953,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_subscribed_workteam(**operation_input_args) # deserialize response and update self @@ -30863,6 +31007,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_subscribed_workteams", summaries_key="SubscribedWorkteams", summary_name="SubscribedWorkteam", @@ -30947,6 +31093,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_tags", summaries_key="Tags", summary_name="Tag", @@ -31393,6 +31541,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeTrainingJobResponse") training_job = cls(**transformed_response) + training_job._set_client_context(session=session, region=region) # Post-processing: synthesize model_artifacts for completed jobs where # the API does not return ModelArtifacts (e.g., serverful Nova training jobs). @@ -31444,7 +31593,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_training_job(**operation_input_args) # deserialize response and update self @@ -31481,7 +31630,7 @@ def update( """ logger.info("Updating training_job resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrainingJobName": self.training_job_name, @@ -31523,7 +31672,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrainingJobName": self.training_job_name, @@ -31554,7 +31703,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "TrainingJobName": self.training_job_name, @@ -31801,6 +31950,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_training_jobs", summaries_key="TrainingJobSummaries", summary_name="TrainingJobSummary", @@ -31989,6 +32140,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeTrainingPlanResponse") training_plan = cls(**transformed_response) + training_plan._set_client_context(session=session, region=region) return training_plan @Base.add_validate_call @@ -32021,7 +32173,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_training_plan(**operation_input_args) # deserialize response and update self @@ -32145,6 +32297,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_training_plans", summaries_key="TrainingPlanSummaries", summary_name="TrainingPlanSummary", @@ -32401,6 +32555,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeTransformJobResponse") transform_job = cls(**transformed_response) + transform_job._set_client_context(session=session, region=region) return transform_job @Base.add_validate_call @@ -32433,7 +32588,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_transform_job(**operation_input_args) # deserialize response and update self @@ -32458,7 +32613,7 @@ def stop(self) -> None: ResourceNotFound: Resource being access is not found. """ - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = { "TransformJobName": self.transform_job_name, @@ -32624,6 +32779,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_transform_jobs", summaries_key="TransformJobSummaries", summary_name="TransformJobSummary", @@ -32798,6 +32955,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeTrialResponse") trial = cls(**transformed_response) + trial._set_client_context(session=session, region=region) return trial @Base.add_validate_call @@ -32830,7 +32988,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_trial(**operation_input_args) # deserialize response and update self @@ -32863,7 +33021,7 @@ def update( """ logger.info("Updating trial resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrialName": self.trial_name, @@ -32901,7 +33059,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrialName": self.trial_name, @@ -32977,6 +33135,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_trials", summaries_key="TrialSummaries", summary_name="TrialSummary", @@ -33181,6 +33341,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeTrialComponentResponse") trial_component = cls(**transformed_response) + trial_component._set_client_context(session=session, region=region) return trial_component @Base.add_validate_call @@ -33213,7 +33374,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_trial_component(**operation_input_args) # deserialize response and update self @@ -33260,7 +33421,7 @@ def update( """ logger.info("Updating trial_component resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrialComponentName": self.trial_component_name, @@ -33307,7 +33468,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "TrialComponentName": self.trial_component_name, @@ -33444,6 +33605,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_trial_components", summaries_key="TrialComponentSummaries", summary_name="TrialComponentSummary", @@ -33488,9 +33651,7 @@ def associate_trail( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling associate_trial_component API") response = client.associate_trial_component(**operation_input_args) @@ -33532,9 +33693,7 @@ def disassociate_trail( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) logger.debug(f"Calling disassociate_trial_component API") response = client.disassociate_trial_component(**operation_input_args) @@ -33575,9 +33734,7 @@ def batch_put_metrics( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker-metrics" - ) + client = self._get_client(service_name="sagemaker-metrics", session=session, region=region) logger.debug(f"Calling batch_put_metrics API") response = client.batch_put_metrics(**operation_input_args) @@ -33856,6 +34013,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeUserProfileResponse") user_profile = cls(**transformed_response) + user_profile._set_client_context(session=session, region=region) return user_profile @Base.add_validate_call @@ -33890,7 +34048,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_user_profile(**operation_input_args) # deserialize response and update self @@ -33925,7 +34083,7 @@ def update( """ logger.info("Updating user_profile resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -33965,7 +34123,7 @@ def delete( ResourceNotFound: Resource being access is not found. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "DomainId": self.domain_id, @@ -34172,6 +34330,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_user_profiles", summaries_key="UserProfiles", summary_name="UserProfileDetails", @@ -34353,6 +34513,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeWorkforceResponse") workforce = cls(**transformed_response) + workforce._set_client_context(session=session, region=region) return workforce @Base.add_validate_call @@ -34384,7 +34545,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_workforce(**operation_input_args) # deserialize response and update self @@ -34426,7 +34587,7 @@ def update( """ logger.info("Updating workforce resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "WorkforceName": self.workforce_name, @@ -34466,7 +34627,7 @@ def delete( ``` """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "WorkforceName": self.workforce_name, @@ -34649,6 +34810,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_workforces", summaries_key="Workforces", summary_name="Workforce", @@ -34811,6 +34974,7 @@ def get( # deserialize the response transformed_response = transform(response, "DescribeWorkteamResponse") workteam = cls(**transformed_response) + workteam._set_client_context(session=session, region=region) return workteam @Base.add_validate_call @@ -34842,7 +35006,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.describe_workteam(**operation_input_args) # deserialize response and update self @@ -34883,7 +35047,7 @@ def update( """ logger.info("Updating workteam resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "WorkteamName": self.workteam_name, @@ -34924,7 +35088,7 @@ def delete( ResourceLimitExceeded: You have exceeded an SageMaker resource limit. For example, you might have too many training jobs created. """ - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = { "WorkteamName": self.workteam_name, @@ -34990,6 +35154,8 @@ def get_all( return ResourceIterator( client=client, + session=session, + region=region, list_method="list_workteams", summaries_key="Workteams", summary_name="Workteam", @@ -35052,12 +35218,12 @@ def get_all_labeling_jobs( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {operation_input_args}") - client = Base.get_sagemaker_client( - session=session, region_name=region, service_name="sagemaker" - ) + client = self._get_client(service_name="sagemaker", session=session, region=region) return ResourceIterator( client=client, + session=session or self._session, + region=region or self._region, list_method="list_labeling_jobs_for_workteam", summaries_key="LabelingJobSummaryList", summary_name="LabelingJobForWorkteamSummary", diff --git a/sagemaker-core/src/sagemaker/core/tools/resources_codegen.py b/sagemaker-core/src/sagemaker/core/tools/resources_codegen.py index 4b729a8a59..d6cc9ba325 100644 --- a/sagemaker-core/src/sagemaker/core/tools/resources_codegen.py +++ b/sagemaker-core/src/sagemaker/core/tools/resources_codegen.py @@ -56,6 +56,7 @@ GENERIC_METHOD_TEMPLATE, GET_METHOD_TEMPLATE, INITIALIZE_CLIENT_TEMPLATE, + INITIALIZE_OBJECT_CLIENT_TEMPLATE, REFRESH_METHOD_TEMPLATE, RESOURCE_BASE_CLASS_TEMPLATE, RETURN_ITERATOR_TEMPLATE, @@ -177,7 +178,7 @@ def generate_imports(self) -> str: "import datetime", "import time", "import functools", - "from pydantic import validate_call", + "from pydantic import PrivateAttr, validate_call", "from typing import Dict, List, Literal, Optional, Union, Any\n" "from boto3.session import Session", "from rich.console import Group", @@ -1406,7 +1407,7 @@ def generate_start_method(self, resource_name: str, **kwargs) -> str: exclude_resource_attrs=exclude_resource_attrs, ) - initialize_client = INITIALIZE_CLIENT_TEMPLATE.format(service_name="sagemaker") + initialize_client = INITIALIZE_OBJECT_CLIENT_TEMPLATE.format(service_name="sagemaker") formatted_method = GENERIC_METHOD_TEMPLATE.format( docstring=docstring, @@ -1456,6 +1457,17 @@ def generate_stop_method(self, resource_name: str) -> str: ) return formatted_method + @staticmethod + def _initialize_client_template(method: Method) -> str: + """Pick the client-initialization template for a generated method. + + Object methods fall back to the session/region the resource was loaded with; + class and static methods only use the arguments passed to them. + """ + if method.method_type in (MethodType.CLASS.value, MethodType.STATIC.value): + return INITIALIZE_CLIENT_TEMPLATE + return INITIALIZE_OBJECT_CLIENT_TEMPLATE + def generate_method(self, method: Method, resource_attributes: list): # TODO: Use special templates for some methods with different formats like list and wait """Generate a resource method from its operation metadata.""" @@ -1501,7 +1513,9 @@ def generate_method(self, method: Method, resource_attributes: list): method_args += add_indent("session: Optional[Session] = None,\n", 4) method_args += add_indent("region: Optional[str] = None,", 4) - initialize_client = INITIALIZE_CLIENT_TEMPLATE.format(service_name=method.service_name) + initialize_client = self._initialize_client_template(method).format( + service_name=method.service_name + ) if len(self.shapes[operation_input_shape_name]["members"]) != 0: # the method has input arguments serialize_operation_input = SERIALIZE_INPUT_TEMPLATE.format( @@ -1540,7 +1554,9 @@ def generate_method(self, method: Method, resource_attributes: list): return_type_conversion=return_type_conversion, ) - initialize_client = INITIALIZE_CLIENT_TEMPLATE.format(service_name=method.service_name) + initialize_client = self._initialize_client_template(method).format( + service_name=method.service_name + ) if len(self.shapes[operation_input_shape_name]["members"]) != 0: # the method has input arguments if method.resource_name == "Endpoint" and method.method_name == "invoke": @@ -1647,8 +1663,16 @@ def generate_additional_get_all_method(self, method: Method, resource_attributes list_method = convert_to_snake_case(method.operation_name) # TODO: add rules for custom key mapping and list methods with no args + if method.method_type in (MethodType.CLASS.value, MethodType.STATIC.value): + client_context_args = ["session=session", "region=region"] + else: + client_context_args = [ + "session=session or self._session", + "region=region or self._region", + ] resource_iterator_args_list = [ "client=client", + *client_context_args, f"list_method='{list_method}'", f"summaries_key='{summaries_key}'", f"summary_name='{summary_name}'", @@ -1661,7 +1685,9 @@ def generate_additional_get_all_method(self, method: Method, resource_attributes serialize_operation_input = SERIALIZE_INPUT_TEMPLATE.format( operation_input_args=operation_input_args ) - initialize_client = INITIALIZE_CLIENT_TEMPLATE.format(service_name=method.service_name) + initialize_client = self._initialize_client_template(method).format( + service_name=method.service_name + ) deserialize_response = RETURN_ITERATOR_TEMPLATE.format( resource_iterator_args=resource_iterator_args ) @@ -1931,6 +1957,8 @@ def generate_get_all_method(self, resource_name: str) -> str: resource_iterator_args_list = [ "client=client", + "session=session", + "region=region", f"list_method='{operation}'", f"summaries_key='{summaries_key}'", f"summary_name='{summary_name}'", diff --git a/sagemaker-core/src/sagemaker/core/tools/templates.py b/sagemaker-core/src/sagemaker/core/tools/templates.py index 3b06111a63..981a9fefc7 100644 --- a/sagemaker-core/src/sagemaker/core/tools/templates.py +++ b/sagemaker-core/src/sagemaker/core/tools/templates.py @@ -156,7 +156,7 @@ def update( ) -> Optional["{resource_name}"]: {docstring} logger.info("Updating {resource_lower} resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = {{ {operation_input_args} @@ -183,7 +183,7 @@ def update( ) -> Optional["{resource_name}"]: {docstring} logger.info("Updating {resource_lower} resource.") - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = {{ {operation_input_args} @@ -240,7 +240,8 @@ def get( # deserialize the response transformed_response = transform(response, '{describe_operation_output_shape}') - {resource_lower} = cls(**transformed_response){post_processing} + {resource_lower} = cls(**transformed_response) + {resource_lower}._set_client_context(session=session, region=region){post_processing} return {resource_lower} """ @@ -258,7 +259,7 @@ def refresh( operation_input_args = serialize(operation_input_args) logger.debug(f"Serialized input request: {{operation_input_args}}") - client = Base.get_sagemaker_client() + client = self._get_client() response = client.{operation}(**operation_input_args) # deserialize response and update self @@ -483,7 +484,7 @@ def delete( {delete_args} ) -> None: {docstring} - client = Base.get_sagemaker_client() + client = self._get_client() operation_input_args = {{ {operation_input_args} @@ -501,7 +502,7 @@ def delete( @Base.add_validate_call def stop(self) -> None: {docstring} - client = SageMakerClient().sagemaker_client + client = self._get_client() operation_input_args = {{ {operation_input_args} @@ -590,6 +591,9 @@ def {method_name}( INITIALIZE_CLIENT_TEMPLATE = """ client = Base.get_sagemaker_client(session=session, region_name=region, service_name='{service_name}')""" +INITIALIZE_OBJECT_CLIENT_TEMPLATE = """ + client = self._get_client(service_name='{service_name}', session=session, region=region)""" + CALL_OPERATION_API_TEMPLATE = """ logger.debug(f"Calling {operation} API") response = client.{operation}(**operation_input_args) @@ -625,11 +629,33 @@ class Base(BaseModel): arbitrary_types_allowed=True, ) config_manager: ClassVar[SageMakerConfig] = SageMakerConfig() + # Session and region the resource was created or loaded with. Object methods + # (refresh, wait, update, delete, stop, ...) reuse them so a resource obtained + # with an explicit session keeps talking to the same account and region. + _session: Optional[Session] = PrivateAttr(default=None) + _region: Optional[str] = PrivateAttr(default=None) @classmethod def get_sagemaker_client(cls, session = None, region_name = None, service_name = 'sagemaker'): return SageMakerClient(session=session, region_name=region_name).get_client(service_name=service_name) + def _set_client_context(self, session: Optional[Session] = None, region: Optional[str] = None): + self._session = session + self._region = region + return self + + def _get_client( + self, + service_name: str = 'sagemaker', + session: Optional[Session] = None, + region: Optional[str] = None, + ): + return Base.get_sagemaker_client( + session=session or self._session, + region_name=region or self._region, + service_name=service_name, + ) + @staticmethod def get_updated_kwargs_with_configured_attributes( config_schema_for_resource: dict, resource_name: str, **kwargs diff --git a/sagemaker-core/src/sagemaker/core/utils/utils.py b/sagemaker-core/src/sagemaker/core/utils/utils.py index 7f8687a42a..15136e64f1 100644 --- a/sagemaker-core/src/sagemaker/core/utils/utils.py +++ b/sagemaker-core/src/sagemaker/core/utils/utils.py @@ -28,7 +28,7 @@ from rich.style import Style from rich.theme import Theme from rich.traceback import install -from typing import Any, Dict, List, TypeVar, Generic, Type +from typing import Any, Dict, List, Optional, TypeVar, Generic, Type from sagemaker.core.utils.code_injection.codec import transform from sagemaker.core.utils.code_injection.constants import Color from sagemaker.core.utils.user_agent import get_user_agent_extra_suffix @@ -478,6 +478,8 @@ def __init__( list_method: str, list_method_kwargs: dict = {}, custom_key_mapping: dict = None, + session=None, + region: Optional[str] = None, ): """Initialize a ResourceIterator object @@ -491,6 +493,10 @@ def __init__( custom_key_mapping (dict, optional): The custom key mapping used to map keys from summary object to those expected from resource object during initialization. Defaults to None. + session (boto3.session.Session, optional): The session the list call was made with. + Each returned resource is bound to it, so its refresh and other object methods + use the same account. Defaults to None (the process default client). + region (str, optional): The region the list call was made in. Defaults to None. """ self.summaries_key = summaries_key self.summary_name = summary_name @@ -498,6 +504,8 @@ def __init__( self.list_method = list_method self.list_method_kwargs = list_method_kwargs self.custom_key_mapping = custom_key_mapping + self.session = session + self.region = region self.resource_cls = resource_cls self.index = 0 @@ -534,6 +542,12 @@ def __next__(self) -> T: resource_object = self.resource_cls(**init_data) + # Bind the resource to the session/region it was listed with + if hasattr(resource_object, "_set_client_context"): + resource_object._set_client_context( # pylint: disable=protected-access + session=self.session, region=self.region + ) + # If the resource object has refresh method, refresh and return it if hasattr(resource_object, "refresh"): resource_object.refresh() diff --git a/sagemaker-core/tests/unit/test_resource_client_context.py b/sagemaker-core/tests/unit/test_resource_client_context.py new file mode 100644 index 0000000000..1cc0819e6e --- /dev/null +++ b/sagemaker-core/tests/unit/test_resource_client_context.py @@ -0,0 +1,116 @@ +"""Generated resources keep using the session/region they were loaded with. + +Regression coverage for #6069: ``TrainingJob.create(session=...)`` used the +caller's session, but ``refresh()``/``wait()``/``stop()`` called +``Base.get_sagemaker_client()`` with no session and fell back to the process +default client, so a job created in one account was polled in another. +""" + +from unittest.mock import MagicMock, patch + +import boto3 +import pytest + +from sagemaker.core.resources import Base, TrainingJob +from sagemaker.core.utils.utils import SageMakerClient + +JOB = "my-job" + + +def _session(key): + return boto3.Session( + aws_access_key_id=key, aws_secret_access_key="secret", region_name="us-west-2" + ) + + +@pytest.fixture(autouse=True) +def _reset_client_cache(): + SageMakerClient.reset() + yield + SageMakerClient.reset() + + +@pytest.fixture +def recorded_clients(): + """Patch Base.get_sagemaker_client; record (session, region) per call.""" + calls = [] + client = MagicMock() + client.describe_training_job.return_value = { + "TrainingJobName": JOB, + "TrainingJobStatus": "Completed", + "SecondaryStatus": "Completed", + } + client.list_training_jobs.return_value = { + "TrainingJobSummaries": [{"TrainingJobName": JOB, "TrainingJobStatus": "Completed"}] + } + + def fake(session=None, region_name=None, service_name="sagemaker"): + calls.append((session, region_name)) + return client + + with patch.object(Base, "get_sagemaker_client", side_effect=fake): + yield calls, client + + +def test_get_binds_session_for_refresh_wait_and_stop(recorded_clients): + calls, _ = recorded_clients + session_b = _session("AKIDB") + + job = TrainingJob.get(JOB, session=session_b, region="eu-west-1") + job.refresh() + job.wait() + job.stop() + + assert calls, "no client was requested" + assert all(call == (session_b, "eu-west-1") for call in calls), calls + + +def test_explicit_session_on_object_method_overrides_bound_one(recorded_clients): + calls, _ = recorded_clients + session_b, session_c = _session("AKIDB"), _session("AKIDC") + + job = TrainingJob.get(JOB, session=session_b) + calls.clear() + job._get_client(session=session_c) + + assert calls == [(session_c, None)] + + +def test_get_all_binds_session_on_each_resource(recorded_clients): + calls, _ = recorded_clients + session_b = _session("AKIDB") + + jobs = list(TrainingJob.get_all(session=session_b, region="eu-west-1")) + + assert [j.training_job_name for j in jobs] == [JOB] + # list call plus the iterator's per-item refresh, all on session_b + assert len(calls) >= 2 + assert all(call == (session_b, "eu-west-1") for call in calls), calls + + +def test_unbound_resource_still_uses_process_default(recorded_clients): + calls, _ = recorded_clients + + TrainingJob(training_job_name=JOB).refresh() + + assert calls == [(None, None)] + + +def test_bound_refresh_signs_with_bound_session_after_default_exists(): + """End to end through SageMakerClient: the default-chain client built first + must not be used by refresh() on a resource loaded with another session.""" + default = SageMakerClient(session=_session("AKIDDEFAULT")) + session_b = _session("AKIDB") + + job = TrainingJob(training_job_name=JOB)._set_client_context(session=session_b) + client = job._get_client() + + assert client is not default.sagemaker_client + assert client._request_signer._credentials.access_key == "AKIDB" + + +def test_client_context_is_not_a_model_field(): + job = TrainingJob(training_job_name=JOB)._set_client_context(session=_session("AKIDB")) + + assert "_session" not in vars(job) + assert "session" not in TrainingJob.model_fields From 59b351ea6d83b0d71db365054a9959c6c10dadf8 Mon Sep 17 00:00:00 2001 From: AMARJEET J Date: Fri, 2 Oct 2026 05:23:43 +0000 Subject: [PATCH 4/4] fix(core): Respect user retry settings over SDK default An explicit botocore Config outranks AWS_MAX_ATTEMPTS, AWS_RETRY_MODE and the shared config file. Now that SageMakerClient's config reaches the boto3 clients, the synthesized standard/10 retries default would silently override those user settings whenever no config is passed. Only synthesize the default when neither the environment nor the active profile configures retries; otherwise pass an empty Config so botocore's own precedence applies. An explicit config= still wins. --- .../src/sagemaker/core/utils/utils.py | 30 ++++++++++- .../tests/unit/test_sagemaker_client.py | 53 ++++++++++++++++++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/sagemaker-core/src/sagemaker/core/utils/utils.py b/sagemaker-core/src/sagemaker/core/utils/utils.py index 15136e64f1..f1268e9a04 100644 --- a/sagemaker-core/src/sagemaker/core/utils/utils.py +++ b/sagemaker-core/src/sagemaker/core/utils/utils.py @@ -430,8 +430,14 @@ def __init__( region_name = session.region_name if config is None: - logger.debug("No config provided. Using default config.") - config = Config(retries={"max_attempts": 10, "mode": "standard"}) + if _retries_configured_outside_code(session): + # An explicit Config outranks env vars and the shared config file, + # so only supply the SDK's retry default when the user set neither. + logger.debug("No config provided. Using retry settings from env/config.") + config = Config() + else: + logger.debug("No config provided. Using default config.") + config = Config(retries={"max_attempts": 10, "mode": "standard"}) # Keep the caller's config object alive: the cache key uses its identity. self._base_config = config @@ -466,6 +472,26 @@ def get_client(self, service_name: str) -> Any: return getattr(self, service_name + "_client") +_RETRY_ENV_VARS = ("AWS_RETRY_MODE", "AWS_MAX_ATTEMPTS") +_RETRY_CONFIG_KEYS = ("retry_mode", "max_attempts") + + +def _retries_configured_outside_code(session: Session) -> bool: + """Return True if the user set retry behaviour via env vars or the shared config file. + + These are the two sources botocore consults for retries when no explicit + ``Config(retries=...)`` is passed; a synthesized one would silently override them. + """ + if any(os.environ.get(name) for name in _RETRY_ENV_VARS): + return True + try: + scoped = session._session.get_scoped_config() + except Exception: # pylint: disable=broad-except + # e.g. ProfileNotFound; botocore will surface that on first call anyway. + return False + return any(key in scoped for key in _RETRY_CONFIG_KEYS) + + class ResourceIterator(Generic[T]): """ResourceIterator class to iterate over a list of resources.""" diff --git a/sagemaker-core/tests/unit/test_sagemaker_client.py b/sagemaker-core/tests/unit/test_sagemaker_client.py index 8e9f92c66b..b165fe64a5 100644 --- a/sagemaker-core/tests/unit/test_sagemaker_client.py +++ b/sagemaker-core/tests/unit/test_sagemaker_client.py @@ -134,7 +134,15 @@ def test_config_argument_is_applied_and_user_agent_suffix_appended(): assert "sagemaker" in meta_config.user_agent_extra.lower() -def test_default_config_keeps_retry_settings(): +@pytest.fixture +def no_user_retry_settings(monkeypatch, tmp_path): + """Isolate from the developer's env vars and ~/.aws/config retry settings.""" + for name in ("AWS_RETRY_MODE", "AWS_MAX_ATTEMPTS", "AWS_PROFILE"): + monkeypatch.delenv(name, raising=False) + monkeypatch.setenv("AWS_CONFIG_FILE", str(tmp_path / "config")) + + +def test_default_config_keeps_retry_settings(no_user_retry_settings): session_a = _session("AKIAFIRSTSESSION0000", REGION_A) client = SageMakerClient(session=session_a) @@ -145,6 +153,49 @@ def test_default_config_keeps_retry_settings(): assert retries["mode"] == "standard" +@pytest.mark.parametrize( + "env, expected", + [ + ({"AWS_MAX_ATTEMPTS": "3"}, {"total_max_attempts": 3}), + ({"AWS_RETRY_MODE": "adaptive"}, {"mode": "adaptive"}), + ], +) +def test_default_config_defers_to_retry_env_vars( + no_user_retry_settings, monkeypatch, env, expected +): + for name, value in env.items(): + monkeypatch.setenv(name, value) + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + + client = SageMakerClient(session=session_a) + + retries = client.sagemaker_client.meta.config.retries + for key, value in expected.items(): + assert retries[key] == value + assert retries.get("total_max_attempts") != 11 + + +def test_default_config_defers_to_shared_config_retries(no_user_retry_settings, tmp_path): + (tmp_path / "config").write_text("[default]\nretry_mode = adaptive\nmax_attempts = 4\n") + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + + client = SageMakerClient(session=session_a) + + retries = client.sagemaker_client.meta.config.retries + assert retries["mode"] == "adaptive" + assert retries["total_max_attempts"] == 4 + + +def test_explicit_config_retries_win_over_env(no_user_retry_settings, monkeypatch): + monkeypatch.setenv("AWS_MAX_ATTEMPTS", "3") + session_a = _session("AKIAFIRSTSESSION0000", REGION_A) + config = Config(retries={"max_attempts": 6, "mode": "standard"}) + + client = SageMakerClient(session=session_a, config=config) + + assert client.sagemaker_client.meta.config.retries["total_max_attempts"] == 7 + + def test_distinct_config_objects_get_distinct_clients(): session_a = _session("AKIAFIRSTSESSION0000", REGION_A) config_1 = Config(connect_timeout=1)