Importing sagemaker.mlops / sagemaker.serve raises NoRegionError without a configured region: AIRHub creates boto3 clients at class definition
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
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
pip install sagemaker==3.27.0- 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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di aws/sagemaker-python-sdk
-
get_base_python_image_uri() returns URIs for unsupported Python versionsForse già presa @Fire162 l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
aws/sagemaker-python-sdk#6539 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug] ModelTrainer with no input channels emits InputDataConfig: [], which CreatePipeline rejects (min=1) — v2 omitted the keyForse già presa @sagemaker-bot l’ha presa 32 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
aws/sagemaker-python-sdk#6156 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
sagemaker-train should depend on mlflow-skinny, following sagemaker-mlflow 0.5.0Forse già presa @mohamedzeidan2021 l’ha presa 32 giorni fa. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
aws/sagemaker-python-sdk#6152 ·
I maintainer di solito rispondono entro 1 giorno
-
`ModelTrainer` bug with method to load hyperparameters from file for Amazon Nova RecipeForse già presa @sagemaker-bot l’ha presa 32 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
aws/sagemaker-python-sdk#5770 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
aws/sagemaker-python-sdk#5588 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di aws/sagemaker-python-sdk
Issue simili
-
ReadQwen3PaperTask5 rejects correct answers that differ only in order, case, or underscore formForse già presa @Kingpython123 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
Tongyi-MAI/MobileWorld#72 ·
-
_threads/application: Update typing annotations using `pyupgrade --py311-plus`Forse già presa @gudnimg l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Health probes return 401 when authentication is enabled and the API is served under /orbForse già presa @fgogolli l’ha presa oggi. Apertaarea: api priority: p2 size: S type: bug
Difficoltà 2/5 Mezza giornata Idoneità per principianti 75/100
finos/open-resource-broker#704 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
BCDA-APS/polar-bits#93 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
GoogleCloudPlatform/gce-rescue#218 ·
I maintainer di solito rispondono entro 2 giorni