Skip to content

sagemaker.Session does not use boto3 DEFAULT_SESSION #1542

@nlothian

Description

@nlothian

Describe the bug
When using multiple profiles, boto3 allows one to set the default: boto3.setup_default_session(profile_name="my_profile_name"). The docs for sagemaker.Session indicate this will be used:

AWS service calls are delegated to an underlying Boto3 session, which by default is initialized using the AWS configuration chain.

But it isn't.

To reproduce

import sagemaker

sagemaker_session = sagemaker.Session()

inputs = sagemaker_session.upload_data(bucket="my-bucket-name", 
                                       path='my-path.tar.gz', 
                                       key_prefix='my-prefix')

Gives: An error occurred (AccessDenied) when calling the CreateMultipartUpload operation: Access Denied

Change this to:

sagemaker_session = sagemaker.Session(boto_session=boto3.session.Session(profile_name="my_profile_name"))

inputs = sagemaker_session.upload_data(bucket="my-bucket-name", 
                                       path='my-path.tar.gz', 
                                       key_prefix='my-prefix')

And works as expected

Expected behavior
It should default to using DEFAULT_SESSION

System information
A description of your system. Please provide:

  • SageMaker Python SDK version: sagemaker==1.60.2

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