Repository navigation
Commit 8fb6729
authored
fix: SageMakerClient honors the passed boto3 session and config (#6273)
* 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
* 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
* 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
* 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.1 parent 1a3cecf commit 8fb6729
6 files changed
Lines changed: 1101 additions & 360 deletions
File tree
- sagemaker-core
- src/sagemaker/core
- tools
- utils
- tests/unit
0 commit comments