Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#6,542 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
aws, python
Ambito
backend, cloud

Direzione di ricerca

Start with sagemaker/ai_registry/air_hub.py and trace how AIRHub creates and uses its SageMaker and S3 boto3 clients, including how callers pass their session. Reproduce the import failure with the provided no-region subprocess command. Done when importing sagemaker.mlops without a configured region succeeds and AIRHub clients use the caller's session.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
2.3k
Fork
1.3k
Merge medio
2g 2h
PR unite (30g)
71

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws/sagemaker-python-sdk

Tutte le issue di aws/sagemaker-python-sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.