Skip to content

Commit 118e832

Browse files
authored
Merge branch 'master' into patch-2
2 parents 45e9e1d + 7bb613e commit 118e832

File tree

8 files changed

+61
-7
lines changed

8 files changed

+61
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v2.9.1 (2020-09-17)
4+
5+
### Bug Fixes and Other Changes
6+
7+
* update spark image_uri config with eu-north-1 account
8+
39
## v2.9.0 (2020-09-17)
410

511
### Features

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.9.1.dev0
1+
2.9.2.dev0

src/sagemaker/processing.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def run(
120120
logs=True,
121121
job_name=None,
122122
experiment_config=None,
123+
kms_key=None,
123124
):
124125
"""Runs a processing job.
125126
@@ -140,6 +141,8 @@ def run(
140141
experiment_config (dict[str, str]): Experiment management configuration.
141142
Dictionary contains three optional keys:
142143
'ExperimentName', 'TrialName', and 'TrialComponentDisplayName'.
144+
kms_key (str): The ARN of the KMS key that is used to encrypt the
145+
user code file (default: None).
143146
144147
Raises:
145148
ValueError: if ``logs`` is True but ``wait`` is False.
@@ -154,6 +157,7 @@ def run(
154157
job_name=job_name,
155158
arguments=arguments,
156159
inputs=inputs,
160+
kms_key=kms_key,
157161
outputs=outputs,
158162
)
159163

@@ -171,7 +175,15 @@ def _extend_processing_args(self, inputs, outputs, **kwargs): # pylint: disable
171175
"""Extend inputs and outputs based on extra parameters"""
172176
return inputs, outputs
173177

174-
def _normalize_args(self, job_name=None, arguments=None, inputs=None, outputs=None, code=None):
178+
def _normalize_args(
179+
self,
180+
job_name=None,
181+
arguments=None,
182+
inputs=None,
183+
outputs=None,
184+
code=None,
185+
kms_key=None,
186+
):
175187
"""Normalizes the arguments so that they can be passed to the job run
176188
177189
Args:
@@ -183,6 +195,8 @@ def _normalize_args(self, job_name=None, arguments=None, inputs=None, outputs=No
183195
inputs (list[:class:`~sagemaker.processing.ProcessingInput`]): Input files for
184196
the processing job. These must be provided as
185197
:class:`~sagemaker.processing.ProcessingInput` objects (default: None).
198+
kms_key (str): The ARN of the KMS key that is used to encrypt the
199+
user code file (default: None).
186200
outputs (list[:class:`~sagemaker.processing.ProcessingOutput`]): Outputs for
187201
the processing job. These can be specified as either path strings or
188202
:class:`~sagemaker.processing.ProcessingOutput` objects (default: None).
@@ -192,7 +206,7 @@ def _normalize_args(self, job_name=None, arguments=None, inputs=None, outputs=No
192206
self._current_job_name = self._generate_current_job_name(job_name=job_name)
193207

194208
inputs_with_code = self._include_code_in_inputs(inputs, code)
195-
normalized_inputs = self._normalize_inputs(inputs_with_code)
209+
normalized_inputs = self._normalize_inputs(inputs_with_code, kms_key)
196210
normalized_outputs = self._normalize_outputs(outputs)
197211
self.arguments = arguments
198212

@@ -234,13 +248,15 @@ def _generate_current_job_name(self, job_name=None):
234248

235249
return name_from_base(base_name)
236250

237-
def _normalize_inputs(self, inputs=None):
251+
def _normalize_inputs(self, inputs=None, kms_key=None):
238252
"""Ensures that all the ``ProcessingInput`` objects have names and S3 URIs.
239253
240254
Args:
241255
inputs (list[sagemaker.processing.ProcessingInput]): A list of ``ProcessingInput``
242256
objects to be normalized (default: None). If not specified,
243257
an empty list is returned.
258+
kms_key (str): The ARN of the KMS key that is used to encrypt the
259+
user code file (default: None).
244260
245261
Returns:
246262
list[sagemaker.processing.ProcessingInput]: The list of normalized
@@ -274,6 +290,7 @@ def _normalize_inputs(self, inputs=None):
274290
local_path=file_input.source,
275291
desired_s3_uri=desired_s3_uri,
276292
sagemaker_session=self.sagemaker_session,
293+
kms_key=kms_key,
277294
)
278295
file_input.source = s3_uri
279296
normalized_inputs.append(file_input)
@@ -413,6 +430,7 @@ def run(
413430
logs=True,
414431
job_name=None,
415432
experiment_config=None,
433+
kms_key=None,
416434
):
417435
"""Runs a processing job.
418436
@@ -435,13 +453,16 @@ def run(
435453
experiment_config (dict[str, str]): Experiment management configuration.
436454
Dictionary contains three optional keys:
437455
'ExperimentName', 'TrialName', and 'TrialComponentDisplayName'.
456+
kms_key (str): The ARN of the KMS key that is used to encrypt the
457+
user code file (default: None).
438458
"""
439459
normalized_inputs, normalized_outputs = self._normalize_args(
440460
job_name=job_name,
441461
arguments=arguments,
442462
inputs=inputs,
443463
outputs=outputs,
444464
code=code,
465+
kms_key=kms_key,
445466
)
446467

447468
self.latest_job = ProcessingJob.start_new(

src/sagemaker/s3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ def upload(local_path, desired_s3_uri, kms_key=None, sagemaker_session=None):
8383
sagemaker_session = sagemaker_session or Session()
8484
bucket, key_prefix = parse_s3_url(url=desired_s3_uri)
8585
if kms_key is not None:
86-
extra_args = {"SSEKMSKeyId": kms_key}
86+
extra_args = {"SSEKMSKeyId": kms_key, "ServerSideEncryption": "aws:kms"}
87+
8788
else:
8889
extra_args = None
8990

src/sagemaker/spark/processing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def run(
180180
logs=True,
181181
job_name=None,
182182
experiment_config=None,
183+
kms_key=None,
183184
):
184185
"""Runs a processing job.
185186
@@ -201,6 +202,8 @@ def run(
201202
experiment_config (dict[str, str]): Experiment management configuration.
202203
Dictionary contains three optional keys:
203204
'ExperimentName', 'TrialName', and 'TrialComponentDisplayName'.
205+
kms_key (str): The ARN of the KMS key that is used to encrypt the
206+
user code file (default: None).
204207
"""
205208
self._current_job_name = self._generate_current_job_name(job_name=job_name)
206209

@@ -213,6 +216,7 @@ def run(
213216
logs,
214217
job_name,
215218
experiment_config,
219+
kms_key,
216220
)
217221

218222
def _extend_processing_args(self, inputs, outputs, **kwargs):
@@ -695,6 +699,7 @@ def run(
695699
experiment_config=None,
696700
configuration=None,
697701
spark_event_logs_s3_uri=None,
702+
kms_key=None,
698703
):
699704
"""Runs a processing job.
700705
@@ -728,6 +733,8 @@ def run(
728733
https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps.html
729734
spark_event_logs_s3_uri (str): S3 path where spark application events will
730735
be published to.
736+
kms_key (str): The ARN of the KMS key that is used to encrypt the
737+
user code file (default: None).
731738
"""
732739
self._current_job_name = self._generate_current_job_name(job_name=job_name)
733740

@@ -872,6 +879,7 @@ def run(
872879
experiment_config=None,
873880
configuration=None,
874881
spark_event_logs_s3_uri=None,
882+
kms_key=None,
875883
):
876884
"""Runs a processing job.
877885
@@ -905,6 +913,8 @@ def run(
905913
https://docs.aws.amazon.com/emr/latest/ReleaseGuide/emr-configure-apps.html
906914
spark_event_logs_s3_uri (str): S3 path where spark application events will
907915
be published to.
916+
kms_key (str): The ARN of the KMS key that is used to encrypt the
917+
user code file (default: None).
908918
"""
909919
self._current_job_name = self._generate_current_job_name(job_name=job_name)
910920

@@ -930,6 +940,7 @@ def run(
930940
logs=logs,
931941
job_name=self._current_job_name,
932942
experiment_config=experiment_config,
943+
kms_key=kms_key,
933944
)
934945

935946
def _extend_processing_args(self, inputs, outputs, **kwargs):

tests/integ/test_processing.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ def volume_kms_key(sagemaker_session):
8585
)
8686

8787

88+
@pytest.fixture(scope="module")
89+
def input_kms_key(sagemaker_session):
90+
role_arn = sagemaker_session.expand_role(ROLE)
91+
return get_or_create_kms_key(
92+
sagemaker_session=sagemaker_session,
93+
role_arn=role_arn,
94+
alias="integ-test-processing-input-kms-key-{}".format(
95+
sagemaker_session.boto_session.region_name
96+
),
97+
)
98+
99+
88100
@pytest.fixture(scope="module")
89101
def output_kms_key(sagemaker_session):
90102
role_arn = sagemaker_session.expand_role(ROLE)
@@ -584,6 +596,7 @@ def test_processor_with_custom_bucket(
584596
image_uri,
585597
cpu_instance_type,
586598
output_kms_key,
599+
input_kms_key,
587600
):
588601
script_path = os.path.join(DATA_DIR, "dummy_script.py")
589602

@@ -609,6 +622,7 @@ def test_processor_with_custom_bucket(
609622
source=script_path, destination="/opt/ml/processing/input/code/", input_name="code"
610623
)
611624
],
625+
kms_key=input_kms_key,
612626
outputs=[
613627
ProcessingOutput(
614628
source="/opt/ml/processing/output/container/path/",

tests/unit/sagemaker/spark/test_processing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_configuration_validation(config, expected, sagemaker_session) -> None:
200200
def test_spark_processor_base_run(mock_super_run, spark_processor_base):
201201
spark_processor_base.run(submit_app="app")
202202

203-
mock_super_run.assert_called_with("app", None, None, None, True, True, None, None)
203+
mock_super_run.assert_called_with("app", None, None, None, True, True, None, None, None)
204204

205205

206206
@pytest.mark.parametrize(
@@ -854,6 +854,7 @@ def test_spark_jar_processor_run(
854854
logs=True,
855855
job_name="jobName",
856856
experiment_config=None,
857+
kms_key=None,
857858
)
858859

859860

tests/unit/test_s3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_upload_with_kms_key(sagemaker_session):
6767
path="/path/to/app.jar",
6868
bucket=BUCKET_NAME,
6969
key_prefix=os.path.join(CURRENT_JOB_NAME, SOURCE_NAME),
70-
extra_args={"SSEKMSKeyId": KMS_KEY},
70+
extra_args={"SSEKMSKeyId": KMS_KEY, "ServerSideEncryption": "aws:kms"},
7171
)
7272

7373

0 commit comments

Comments
 (0)