Skip to content

Add a check for S3 paths being incorrectly passed as an entry point #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/sagemaker/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def __init__(self, entry_point, source_dir=None, hyperparameters=None, enable_cl
"""Base class initializer. Subclasses which override ``__init__`` should invoke ``super()``

Args:
entry_point (str): Path (absolute or relative) to the Python source file which should be executed
entry_point (str): Path (absolute or relative) to the local Python source file which should be executed
as the entry point to training. This should be compatible with either Python 2.7 or Python 3.5.
source_dir (str): Path (absolute or relative) to a directory with any other training
source code dependencies aside from tne entry point file (default: None). Structure within this
Expand Down Expand Up @@ -779,9 +779,11 @@ def __init__(self, entry_point, source_dir=None, hyperparameters=None, enable_cl
**kwargs: Additional kwargs passed to the ``EstimatorBase`` constructor.
"""
super(Framework, self).__init__(**kwargs)
if entry_point.startswith('s3://'):
raise ValueError('Invalid entry point script: {}. Must be a path to a local file.'.format(entry_point))
self.entry_point = entry_point
self.source_dir = source_dir
self.dependencies = dependencies or []
self.entry_point = entry_point
if enable_cloudwatch_metrics:
warnings.warn('enable_cloudwatch_metrics is now deprecated and will be removed in the future.',
DeprecationWarning)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ def test_framework_all_init_args(sagemaker_session):
'metric_definitions': [{'Name': 'validation-rmse', 'Regex': 'validation-rmse=(\\d+)'}]}


def test_framework_init_s3_entry_point_invalid(sagemaker_session):
with pytest.raises(ValueError) as error:
DummyFramework('s3://remote-script-because-im-mistaken', role=ROLE,
sagemaker_session=sagemaker_session, train_instance_count=INSTANCE_COUNT,
train_instance_type=INSTANCE_TYPE)
assert 'Must be a path to a local file' in str(error)


def test_sagemaker_s3_uri_invalid(sagemaker_session):
with pytest.raises(ValueError) as error:
t = DummyFramework(entry_point=SCRIPT_PATH, role=ROLE, sagemaker_session=sagemaker_session,
Expand Down