Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sagemaker-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authors = [
readme = "README.rst"
dependencies = [
# Add your dependencies here (Include lower and upper bounds as applicable)
"boto3>=1.42.2,<2.0.0",
"boto3>=1.43.20,<2.0.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

"pydantic>=2.0.0,<3.0.0",
"PyYAML>=6.0, <7.0",
"jsonschema<5.0.0",
Expand Down
47 changes: 3 additions & 44 deletions sagemaker-core/src/sagemaker/core/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class SageMakerClient(metaclass=SingletonMeta):

@classmethod
def reset(cls):
"""Reset the singleton instance so the next call re-reads env vars."""
"""Reset the singleton instance."""
SingletonMeta._instances.pop(cls, None)

def __init__(
Expand Down Expand Up @@ -368,53 +368,12 @@ def __init__(
self.config = Config(user_agent_extra=get_user_agent_extra_suffix())
self.session = session
self.region_name = region_name
# Read region from environment variable, default to us-west-2
import os
env_region = os.environ.get('SAGEMAKER_REGION', region_name)
env_stage = os.environ.get('SAGEMAKER_STAGE', 'prod') # default to gamma
logger.info(f"Runs on sagemaker {env_stage}, region:{env_region}")

endpoint_url = os.environ.get('SAGEMAKER_ENDPOINT')
runtime_endpoint_url = os.environ.get('SAGEMAKER_RUNTIME_ENDPOINT')

# TODO: Remove post-launch. This loads a custom botocore service model
# (from the 'sample/' directory) that includes pre-GA Job APIs
# (CreateJob, DescribeJob, ListJobs, etc.) not yet in the public
# botocore release. Once these APIs ship in the official botocore
# service-2.json, this custom loader is unnecessary and the standard
# session.client("sagemaker", endpoint_url=...) path will work.
#
# NOTE: The custom data loader is registered on the caller-provided
# session's underlying botocore session so that the "sagemaker"
# control-plane client keeps the caller's credentials/profile. Using a
# fresh botocore.session.get_session() here would silently fall back to
# the default AWS profile and break cross-account calls (issue #6069).
import botocore.loaders
import pathlib

# Look for bundled service model inside the package first,
# fall back to source-tree layout (sample/ as sibling of src/)
_bundled = pathlib.Path(__file__).resolve().parent.parent / "data" / "sample"
_source_tree = pathlib.Path(__file__).resolve().parent.parent.parent.parent.parent / "sample"
sample_model_dir = str(_bundled if _bundled.exists() else _source_tree)
loader = botocore.loaders.Loader(
extra_search_paths=[sample_model_dir],
include_default_search_paths=True,
)
# boto3.Session exposes its underlying botocore session as `_session`.
session._session.register_component('data_loader', loader)

self.sagemaker_client = session.client(
"sagemaker",
region_name=env_region,
endpoint_url=endpoint_url,
config=self.config,
"sagemaker", region_name, config=self.config
)

self.sagemaker_runtime_client = session.client(
"sagemaker-runtime", region_name,
endpoint_url=runtime_endpoint_url,
config=self.config,
"sagemaker-runtime", region_name, config=self.config
)
self.sagemaker_featurestore_runtime_client = session.client(
"sagemaker-featurestore-runtime", region_name, config=self.config
Expand Down
Loading