@@ -219,14 +219,14 @@ def _normalize_args(
219
219
"""
220
220
self ._current_job_name = self ._generate_current_job_name (job_name = job_name )
221
221
222
- inputs_with_code = self ._include_code_in_inputs (inputs , code )
222
+ inputs_with_code = self ._include_code_in_inputs (inputs , code , kms_key )
223
223
normalized_inputs = self ._normalize_inputs (inputs_with_code , kms_key )
224
224
normalized_outputs = self ._normalize_outputs (outputs )
225
225
self .arguments = arguments
226
226
227
227
return normalized_inputs , normalized_outputs
228
228
229
- def _include_code_in_inputs (self , inputs , _code ):
229
+ def _include_code_in_inputs (self , inputs , _code , kms_key = None ):
230
230
"""A no op in the base class to include code in the processing job inputs.
231
231
232
232
Args:
@@ -235,6 +235,8 @@ def _include_code_in_inputs(self, inputs, _code):
235
235
:class:`~sagemaker.processing.ProcessingInput` objects.
236
236
_code (str): This can be an S3 URI or a local path to a file with the framework
237
237
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).
238
240
239
241
Returns:
240
242
list[:class:`~sagemaker.processing.ProcessingInput`]: inputs
@@ -528,7 +530,7 @@ def run(
528
530
if wait :
529
531
self .latest_job .wait (logs = logs )
530
532
531
- def _include_code_in_inputs (self , inputs , code ):
533
+ def _include_code_in_inputs (self , inputs , code , kms_key = None ):
532
534
"""Converts code to appropriate input and includes in input list.
533
535
534
536
Side effects include:
@@ -541,12 +543,14 @@ def _include_code_in_inputs(self, inputs, code):
541
543
:class:`~sagemaker.processing.ProcessingInput` objects.
542
544
code (str): This can be an S3 URI or a local path to a file with the framework
543
545
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).
544
548
545
549
Returns:
546
550
list[:class:`~sagemaker.processing.ProcessingInput`]: inputs together with the
547
551
code as `ProcessingInput`.
548
552
"""
549
- user_code_s3_uri = self ._handle_user_code_url (code )
553
+ user_code_s3_uri = self ._handle_user_code_url (code , kms_key )
550
554
user_script_name = self ._get_user_code_name (code )
551
555
552
556
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):
567
571
code_url = urlparse (code )
568
572
return os .path .basename (code_url .path )
569
573
570
- def _handle_user_code_url (self , code ):
574
+ def _handle_user_code_url (self , code , kms_key = None ):
571
575
"""Gets the S3 URL containing the user's code.
572
576
573
577
Inspects the scheme the customer passed in ("s3://" for code in S3, "file://" or nothing
574
578
for absolute or local file paths. Uploads the code to S3 if the code is a local file.
575
579
576
580
Args:
577
581
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).
578
584
579
585
Returns:
580
586
str: The S3 URL to the customer's code.
@@ -603,7 +609,7 @@ def _handle_user_code_url(self, code):
603
609
code
604
610
)
605
611
)
606
- user_code_s3_uri = self ._upload_code (code_path )
612
+ user_code_s3_uri = self ._upload_code (code_path , kms_key )
607
613
else :
608
614
raise ValueError (
609
615
"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):
612
618
)
613
619
return user_code_s3_uri
614
620
615
- def _upload_code (self , code ):
621
+ def _upload_code (self , code , kms_key = None ):
616
622
"""Uploads a code file or directory specified as a string and returns the S3 URI.
617
623
618
624
Args:
619
625
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).
620
628
621
629
Returns:
622
630
str: The S3 URI of the uploaded file or directory.
@@ -630,7 +638,7 @@ def _upload_code(self, code):
630
638
self ._CODE_CONTAINER_INPUT_NAME ,
631
639
)
632
640
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
634
642
)
635
643
636
644
def _convert_code_and_add_to_inputs (self , inputs , s3_uri ):
0 commit comments