SageMakerClient CustomSession uses default values instead of passed user session
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- aws, python
調査の方向性
sagemaker-core/src/sagemaker/core/utils/utils.py の SageMakerClient.init 付近(おおよそ395–406行目)から始め、sagemaker-runtime、featurestore、metrics の各クライアントが渡されたセッションをどのように使用しているかを比較します。提供されている複数プロファイルの再現手順を実行し、CreateTrainingJob がデフォルトプロファイルではなく、指定されたアカウントとリージョンを使用することを確認します。
索引モデルが issue の本文から書いたものです。
説明
PySDK Version
- PySDK V2 (2.x)
- PySDK V3 (3.x)
Describe the bug
SageMakerClient builds the sagemaker client from botocore.session.get_session(), ignoring the provided user session resulting in cross-account CreateTrainingJob failures.
In sagemaker-core 2.16.0, SageMakerClient.init (sagemaker/core/utils/utils.py, ~L395–406) creates self.sagemaker_client from a fresh default botocore session (botocore.session.get_session() → custom_session) rather than the session argument, under a # TODO: Remove post-launch custom service-model loader. The sagemaker-runtime/featurestore/metrics clients correctly use session. Because the class is a SingletonMeta singleton, the first (default-credential) client is reused process-wide ignoring passed in user sessions.
Impact: callers that pass an explicit boto3 session (e.g. ModelTrainer(sagemaker_session=…) → TrainingJob.create(session=…)) have the control-plane call issued under the ambient default AWS profile instead. When the execution role is in a different account than the default profile, CreateTrainingJob fails with ValidationException: RoleArn: Cross-account pass role is not allowed.
To reproduce
If a user has multiple AWS profiles (all for different accounts) set up in ~/.aws/config and the default in ~/.aws/credentials is NOT the same account as the intended profile that is used to create the SageMaker Session then CreateTrainingJob will fail with ValidationException: RoleArn: Cross-account pass role is not allowed.
from sagemaker.core.helper.session_helper import Session
from sagemaker.train import ModelTrainer
from sagemaker.train.configs import SourceCode, Compute, InputData
import boto3
sess = Session(boto_session=boto3.Session(profile_name="acct-A", region_name="us-east-2"))
ModelTrainer(
sagemaker_session=sess, # account A
role="arn:aws:iam::<ACCOUNT_A>:role/<your-exec-role>", # account A
training_image="<ACCOUNT_A>.dkr.ecr.us-east-2.amazonaws.com/img:latest",
compute=Compute(instance_type="ml.m5.xlarge", instance_count=1),
source_code=SourceCode(source_dir="src", entry_script="train.py"),
).train(input_data_config=[InputData(channel_name="train", data_source="s3://bucket/train/")])
# -> ValidationException: RoleArn: Cross-account pass role is not allowed
# (only when your *default* AWS profile is a different account than A)
Expected behavior
A training job to be created and executed in the specified account. This is a migration from v2 to v3 and the v2 implementation of this works without issue creating training jobs in the targeted accounts based on the profile passed to the Session.
Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.
System information
A description of your system. Please provide:
- SageMaker Python SDK version: 3.15.1
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): SKLearn
- Framework version: 1.4-2
- Python version: py3
- CPU or GPU: CPU
- Custom Docker image (Y/N): N
Additional context
This issue also seems to persist to the latest version of 3.16 since the same custom_session is also used to initiate the sagemaker_client.
- 主要言語
- Python
- スター
- 2.3k
- フォーク
- 1.3k
- 平均マージ
- 3日 7時間
- マージ済み PR(30日)
- 87
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws/sagemaker-python-sdk のほかの issue
-
Cannot use spark_event_logs_s3_uri in PySparkProcessor job対応中かも @rsareddy0329 が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
aws/sagemaker-python-sdk#6253 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] V3 Hyperparameter Tuning Pipeline page labelled "Download Data" in navigation due to missing title cell対応中かも @admivsn が 36 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 93/100
aws/sagemaker-python-sdk#6232 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] ModelTrainer with no input channels emits InputDataConfig: [], which CreatePipeline rejects (min=1) — v2 omitted the key対応中かも @sagemaker-bot が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws/sagemaker-python-sdk#6156 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
sagemaker-train should depend on mlflow-skinny, following sagemaker-mlflow 0.5.0対応中かも @mohamedzeidan2021 が 9 日前に担当しました。 オープン
難易度 2/5 半日 初心者へのやさしさ 72/100
aws/sagemaker-python-sdk#6152 ·
メンテナーはふだん 2 日以内に返信
-
ModelTrainer generates sm_train.sh with CRLF line endings on Windows causing training job failure対応中かも @MohammedAlkindi が 27 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
aws/sagemaker-python-sdk#5904 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
aws/sagemaker-python-sdk の issue をすべて見る
似ている issue
-
Link Checker Reportオープンautomated issue report
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
RapidAI/RapidOCRDocs#119 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
btclib-org/btclib-node#1833 ·
メンテナーはふだん 1 日以内に返信
-
IRIS reader: no-data velocity bins (DB_VEL, DB_VELC) returned as 0.0 m/s instead of NaN対応中かも @syedhamidali が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
elodin-sys/elodin#890 ·
メンテナーはふだん 1 日以内に返信