Skip to content

Importing sagemaker.mlops / sagemaker.serve raises NoRegionError without a configured region: AIRHub creates boto3 clients at class definition #6542

Open

Description

@brifordwylie

PySDK Version

  • PySDK V2 (2.x)
  • PySDK V3 (3.x)

Describe the bug
Importing sagemaker.mlops (or sagemaker.serve) raises botocore.exceptions.NoRegionError when no AWS region is configured. sagemaker/ai_registry/air_hub.py creates boto3 clients as class attributes, so they run at import time:

class AIRHub:
    _sagemaker_client = boto3.client("sagemaker")
    _s3_client = boto3.client("s3")

The import chain is sagemaker.mlops → sagemaker.serve.model_builder → sagemaker.train.multi_turn_rl_trainer → sagemaker.ai_registry.dataset → sagemaker.ai_registry.air_hub.

Any package that imports sagemaker.mlops.feature_store therefore can't be imported in CI runners, docs builds, or first-run setup tools. When a region is present, these clients are bound to the default credential chain at import, regardless of the session a caller later passes (the same class of problem as #5986).

To reproduce

  1. pip install sagemaker==3.27.0
  2. Run with no AWS region available:
import os, subprocess, sys

env = {k: v for k, v in os.environ.items() if not k.startswith("AWS_")}
env.update(AWS_CONFIG_FILE=os.devnull, AWS_SHARED_CREDENTIALS_FILE=os.devnull)
subprocess.run([sys.executable, "-c", "import sagemaker.mlops"], env=env, check=True)

Expected behavior
Importing the SDK has no AWS side effects. AIRHub should create its clients lazily, on first use and from the caller's session, so imports succeed without a region and the clients honor the session passed in.

Screenshots or logs

  File ".../sagemaker/mlops/__init__.py", line 25, in <module>
    from sagemaker.serve.model_builder import ModelBuilder
  File ".../sagemaker/serve/model_builder.py", line 73, in <module>
    from sagemaker.train.multi_turn_rl_trainer import MultiTurnRLTrainer
  File ".../sagemaker/train/multi_turn_rl_trainer.py", line 25, in <module>
    from sagemaker.ai_registry.dataset import DataSet
  File ".../sagemaker/ai_registry/dataset.py", line 29, in <module>
    from sagemaker.ai_registry.air_hub import AIRHub
  File ".../sagemaker/ai_registry/air_hub.py", line 36, in AIRHub
    _sagemaker_client = boto3.client("sagemaker")
  ...
botocore.exceptions.NoRegionError: You must specify a region.

System information

  • SageMaker Python SDK version: 3.27.0 (sagemaker-core 2.27.0, sagemaker-train 1.27.0, sagemaker-serve 1.27.0, sagemaker-mlops 1.27.0). Also present in 3.24.0 and on master.
  • Framework name (eg. PyTorch) or algorithm (eg. KMeans): N/A (import-time failure)
  • Framework version: N/A
  • Python version: 3.13 (reproduced on Windows GitHub Actions runners and macOS)
  • CPU or GPU: CPU
  • Custom Docker image (Y/N): N

Additional context
We worked around it by importing sagemaker.mlops lazily, inside the functions that use it. sagemaker.core and sagemaker.train.model_trainer import fine without a region; only paths that reach sagemaker.ai_registry fail.

Activity

  1. brifordwylie commented on Oct 28, 2026

    @brifordwylie
    ContributorAuthor

    @jam-jee just because I've seen your great work on other issues :) (the same class of problem as #5986)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions