Skip to content

Commit 8e65b1f

Browse files
author
Quentin R. Voglund
committed
fix code upload failure
1 parent f399fb7 commit 8e65b1f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/sagemaker/processing.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ def _normalize_args(
219219
"""
220220
self._current_job_name = self._generate_current_job_name(job_name=job_name)
221221

222-
inputs_with_code = self._include_code_in_inputs(inputs, code)
222+
inputs_with_code = self._include_code_in_inputs(inputs, code, kms_key)
223223
normalized_inputs = self._normalize_inputs(inputs_with_code, kms_key)
224224
normalized_outputs = self._normalize_outputs(outputs)
225225
self.arguments = arguments
226226

227227
return normalized_inputs, normalized_outputs
228228

229-
def _include_code_in_inputs(self, inputs, _code):
229+
def _include_code_in_inputs(self, inputs, _code, kms_key=None):
230230
"""A no op in the base class to include code in the processing job inputs.
231231
232232
Args:
@@ -235,6 +235,8 @@ def _include_code_in_inputs(self, inputs, _code):
235235
:class:`~sagemaker.processing.ProcessingInput` objects.
236236
_code (str): This can be an S3 URI or a local path to a file with the framework
237237
script to run (default: None). A no op in the base class.
238+
kms_key (str): The ARN of the KMS key that is used to encrypt the
239+
user code file (default: None).
238240
239241
Returns:
240242
list[:class:`~sagemaker.processing.ProcessingInput`]: inputs
@@ -528,7 +530,7 @@ def run(
528530
if wait:
529531
self.latest_job.wait(logs=logs)
530532

531-
def _include_code_in_inputs(self, inputs, code):
533+
def _include_code_in_inputs(self, inputs, code, kms_key=None):
532534
"""Converts code to appropriate input and includes in input list.
533535
534536
Side effects include:
@@ -541,12 +543,14 @@ def _include_code_in_inputs(self, inputs, code):
541543
:class:`~sagemaker.processing.ProcessingInput` objects.
542544
code (str): This can be an S3 URI or a local path to a file with the framework
543545
script to run (default: None).
546+
kms_key (str): The ARN of the KMS key that is used to encrypt the
547+
user code file (default: None).
544548
545549
Returns:
546550
list[:class:`~sagemaker.processing.ProcessingInput`]: inputs together with the
547551
code as `ProcessingInput`.
548552
"""
549-
user_code_s3_uri = self._handle_user_code_url(code)
553+
user_code_s3_uri = self._handle_user_code_url(code, kms_key)
550554
user_script_name = self._get_user_code_name(code)
551555

552556
inputs_with_code = self._convert_code_and_add_to_inputs(inputs, user_code_s3_uri)
@@ -567,14 +571,16 @@ def _get_user_code_name(self, code):
567571
code_url = urlparse(code)
568572
return os.path.basename(code_url.path)
569573

570-
def _handle_user_code_url(self, code):
574+
def _handle_user_code_url(self, code, kms_key=None):
571575
"""Gets the S3 URL containing the user's code.
572576
573577
Inspects the scheme the customer passed in ("s3://" for code in S3, "file://" or nothing
574578
for absolute or local file paths. Uploads the code to S3 if the code is a local file.
575579
576580
Args:
577581
code (str): A URL to the customer's code.
582+
kms_key (str): The ARN of the KMS key that is used to encrypt the
583+
user code file (default: None).
578584
579585
Returns:
580586
str: The S3 URL to the customer's code.
@@ -603,7 +609,7 @@ def _handle_user_code_url(self, code):
603609
code
604610
)
605611
)
606-
user_code_s3_uri = self._upload_code(code_path)
612+
user_code_s3_uri = self._upload_code(code_path, kms_key)
607613
else:
608614
raise ValueError(
609615
"code {} url scheme {} is not recognized. Please pass a file path or S3 url".format(
@@ -612,11 +618,13 @@ def _handle_user_code_url(self, code):
612618
)
613619
return user_code_s3_uri
614620

615-
def _upload_code(self, code):
621+
def _upload_code(self, code, kms_key=None):
616622
"""Uploads a code file or directory specified as a string and returns the S3 URI.
617623
618624
Args:
619625
code (str): A file or directory to be uploaded to S3.
626+
kms_key (str): The ARN of the KMS key that is used to encrypt the
627+
user code file (default: None).
620628
621629
Returns:
622630
str: The S3 URI of the uploaded file or directory.
@@ -630,7 +638,7 @@ def _upload_code(self, code):
630638
self._CODE_CONTAINER_INPUT_NAME,
631639
)
632640
return s3.S3Uploader.upload(
633-
local_path=code, desired_s3_uri=desired_s3_uri, sagemaker_session=self.sagemaker_session
641+
local_path=code, desired_s3_uri=desired_s3_uri, kms_key=kms_key, sagemaker_session=self.sagemaker_session
634642
)
635643

636644
def _convert_code_and_add_to_inputs(self, inputs, s3_uri):

0 commit comments

Comments
 (0)