Repository navigation
Description
PySDK Version
- PySDK V2 (2.x)
- PySDK V3 (3.x)
Describe the bug
Transformer submits the transform job through its configured
sagemaker_session.
After submission, it creates TransformJob(**transformed) without a boto
session or region. TransformJob.wait() then uses the default boto session.
If the configured and default sessions use different accounts or regions, the
job starts correctly but the wait fails. Common errors include
ResourceNotFound, NoRegionError, and authorization failures.
The same problem affects Transformer.wait() and stop_transform_job()
because they use the same latest_transform_job resource.
Local mode also uses the default AWS resource while waiting. The job exists
only in the local session, so the wait can call AWS for a local job.
This defect is present in SageMaker Python SDK v3.25.0.
To reproduce
Create a SageMaker model and input object in the target account. Configure a
second profile for a different account or region.
Set these environment variables:
export TARGET_PROFILE="<profile-that-owns-the-model>"
export DEFAULT_PROFILE="<different-profile>"
export TARGET_REGION="us-east-2"
export DEFAULT_REGION="us-east-1"
export MODEL_NAME="<existing-model-name>"
export INPUT_S3_URI="s3://<target-bucket>/input/"
export OUTPUT_S3_URI="s3://<target-bucket>/output/"Run this script:
import os
import boto3
from sagemaker.core.helper.session_helper import Session
from sagemaker.core.transformer import Transformer
boto3.setup_default_session(
profile_name=os.environ["DEFAULT_PROFILE"],
region_name=os.environ["DEFAULT_REGION"],
)
target_boto_session = boto3.Session(
profile_name=os.environ["TARGET_PROFILE"],
region_name=os.environ["TARGET_REGION"],
)
target_session = Session(boto_session=target_boto_session)
transformer = Transformer(
model_name=os.environ["MODEL_NAME"],
instance_count=1,
instance_type="ml.m5.large",
output_path=os.environ["OUTPUT_S3_URI"],
sagemaker_session=target_session,
)
transformer.transform(
data=os.environ["INPUT_S3_URI"],
wait=True,
logs=False,
)The target account receives the transform job. The wait uses the default
profile and fails to find that job.
Expected behavior
Submission, wait, stop, and log operations must use the configured
sagemaker_session.
Local transforms must use the local session and must not call a real AWS
endpoint.
Screenshots or logs
Transformer.transform() currently creates the resource without a session:
self.latest_transform_job = TransformJob(**transformed)
if wait:
self.latest_transform_job.wait(logs=logs)Other methods already preserve the session. For example,
Transformer.delete_model() passes self.sagemaker_session.boto_session to
Model.get().
System information
- SageMaker Python SDK version: 3.25.0
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): Framework-independent
- Framework version: Not applicable
- Python version: 3.12
- CPU or GPU: CPU
- Custom Docker image (Y/N): Reproduces with either
Additional context
A possible remote-mode fix is to retrieve the resource with the configured
boto session:
self.latest_transform_job = TransformJob.get(
transform_job_name=transform_args["job_name"],
session=self.sagemaker_session.boto_session,
region=self.sagemaker_session.boto_region_name,
)Local mode needs an equivalent local-session wait path. The implementation
must not replace a local job with an AWS TransformJob resource.
Activity