38
38
from sagemaker .workflow .conditions import ConditionGreaterThanOrEqualTo
39
39
from sagemaker .workflow .condition_step import ConditionStep
40
40
from sagemaker .dataset_definition .inputs import DatasetDefinition , AthenaDatasetDefinition
41
+ from sagemaker .workflow .execution_variables import ExecutionVariables
42
+ from sagemaker .workflow .functions import Join
41
43
from sagemaker .workflow .parameters import (
42
44
ParameterInteger ,
43
45
ParameterString ,
@@ -72,16 +74,9 @@ def role(sagemaker_session):
72
74
return get_execution_role (sagemaker_session )
73
75
74
76
75
- # TODO-reinvent-2020: remove use of specific region and this session
76
77
@pytest .fixture (scope = "module" )
77
- def region ():
78
- return "us-east-2"
79
-
80
-
81
- # TODO-reinvent-2020: remove use of specific region and this session
82
- @pytest .fixture (scope = "module" )
83
- def workflow_session (region ):
84
- boto_session = boto3 .Session (region_name = region )
78
+ def workflow_session (region_name ):
79
+ boto_session = boto3 .Session (region_name = region_name )
85
80
86
81
sagemaker_client_config = dict ()
87
82
sagemaker_client_config .setdefault ("config" , Config (retries = dict (max_attempts = 2 )))
@@ -134,6 +129,7 @@ def test_three_step_definition(
134
129
framework_version = "0.20.0"
135
130
instance_type = ParameterString (name = "InstanceType" , default_value = "ml.m5.xlarge" )
136
131
instance_count = ParameterInteger (name = "InstanceCount" , default_value = 1 )
132
+ output_prefix = ParameterString (name = "OutputPrefix" , default_value = "output" )
137
133
138
134
input_data = f"s3://sagemaker-sample-data-{ region_name } /processing/census/census-income.csv"
139
135
@@ -154,7 +150,20 @@ def test_three_step_definition(
154
150
],
155
151
outputs = [
156
152
ProcessingOutput (output_name = "train_data" , source = "/opt/ml/processing/train" ),
157
- ProcessingOutput (output_name = "test_data" , source = "/opt/ml/processing/test" ),
153
+ ProcessingOutput (
154
+ output_name = "test_data" ,
155
+ source = "/opt/ml/processing/test" ,
156
+ destination = Join (
157
+ on = "/" ,
158
+ values = [
159
+ "s3:/" ,
160
+ sagemaker_session .default_bucket (),
161
+ "test-sklearn" ,
162
+ output_prefix ,
163
+ ExecutionVariables .PIPELINE_EXECUTION_ID ,
164
+ ],
165
+ ),
166
+ ),
158
167
],
159
168
code = os .path .join (script_dir , "preprocessing.py" ),
160
169
)
@@ -194,7 +203,7 @@ def test_three_step_definition(
194
203
195
204
pipeline = Pipeline (
196
205
name = pipeline_name ,
197
- parameters = [instance_type , instance_count ],
206
+ parameters = [instance_type , instance_count , output_prefix ],
198
207
steps = [step_process , step_train , step_model ],
199
208
sagemaker_session = workflow_session ,
200
209
)
@@ -208,6 +217,7 @@ def test_three_step_definition(
208
217
{"Name" : "InstanceType" , "Type" : "String" , "DefaultValue" : "ml.m5.xlarge" }.items ()
209
218
),
210
219
tuple ({"Name" : "InstanceCount" , "Type" : "Integer" , "DefaultValue" : 1 }.items ()),
220
+ tuple ({"Name" : "OutputPrefix" , "Type" : "String" , "DefaultValue" : "output" }.items ()),
211
221
]
212
222
)
213
223
@@ -251,17 +261,28 @@ def test_three_step_definition(
251
261
assert model_args ["PrimaryContainer" ]["ModelDataUrl" ] == {
252
262
"Get" : "Steps.my-train.ModelArtifacts.S3ModelArtifacts"
253
263
}
264
+ try :
265
+ response = pipeline .create (role )
266
+ create_arn = response ["PipelineArn" ]
267
+ assert re .match (
268
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } " ,
269
+ create_arn ,
270
+ )
271
+ finally :
272
+ try :
273
+ pipeline .delete ()
274
+ except Exception :
275
+ pass
254
276
255
277
256
- # TODO-reinvent-2020: Modify use of the workflow client
257
278
def test_one_step_sklearn_processing_pipeline (
258
279
sagemaker_session ,
259
280
workflow_session ,
260
281
role ,
261
282
sklearn_latest_version ,
262
283
cpu_instance_type ,
263
284
pipeline_name ,
264
- region ,
285
+ region_name ,
265
286
athena_dataset_definition ,
266
287
):
267
288
instance_count = ParameterInteger (name = "InstanceCount" , default_value = 2 )
@@ -305,21 +326,21 @@ def test_one_step_sklearn_processing_pipeline(
305
326
response = pipeline .create (role )
306
327
create_arn = response ["PipelineArn" ]
307
328
assert re .match (
308
- fr"arn:aws:sagemaker:{ region } :\d{{12}}:pipeline/{ pipeline_name } " ,
329
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } " ,
309
330
create_arn ,
310
331
)
311
332
312
333
pipeline .parameters = [ParameterInteger (name = "InstanceCount" , default_value = 1 )]
313
334
response = pipeline .update (role )
314
335
update_arn = response ["PipelineArn" ]
315
336
assert re .match (
316
- fr"arn:aws:sagemaker:{ region } :\d{{12}}:pipeline/{ pipeline_name } " ,
337
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } " ,
317
338
update_arn ,
318
339
)
319
340
320
341
execution = pipeline .start (parameters = {})
321
342
assert re .match (
322
- fr"arn:aws:sagemaker:{ region } :\d{{12}}:pipeline/{ pipeline_name } /execution/" ,
343
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } /execution/" ,
323
344
execution .arn ,
324
345
)
325
346
@@ -340,14 +361,13 @@ def test_one_step_sklearn_processing_pipeline(
340
361
pass
341
362
342
363
343
- # TODO-reinvent-2020: Modify use of the workflow client
344
364
def test_conditional_pytorch_training_model_registration (
345
365
sagemaker_session ,
346
366
workflow_session ,
347
367
role ,
348
368
cpu_instance_type ,
349
369
pipeline_name ,
350
- region ,
370
+ region_name ,
351
371
):
352
372
base_dir = os .path .join (DATA_DIR , "pytorch_mnist" )
353
373
entry_point = os .path .join (base_dir , "mnist.py" )
@@ -420,18 +440,18 @@ def test_conditional_pytorch_training_model_registration(
420
440
response = pipeline .create (role )
421
441
create_arn = response ["PipelineArn" ]
422
442
assert re .match (
423
- fr"arn:aws:sagemaker:{ region } :\d{{12}}:pipeline/{ pipeline_name } " , create_arn
443
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } " , create_arn
424
444
)
425
445
426
446
execution = pipeline .start (parameters = {})
427
447
assert re .match (
428
- fr"arn:aws:sagemaker:{ region } :\d{{12}}:pipeline/{ pipeline_name } /execution/" ,
448
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } /execution/" ,
429
449
execution .arn ,
430
450
)
431
451
432
452
execution = pipeline .start (parameters = {"GoodEnoughInput" : 0 })
433
453
assert re .match (
434
- fr"arn:aws:sagemaker:{ region } :\d{{12}}:pipeline/{ pipeline_name } /execution/" ,
454
+ fr"arn:aws:sagemaker:{ region_name } :\d{{12}}:pipeline/{ pipeline_name } /execution/" ,
435
455
execution .arn ,
436
456
)
437
457
finally :
0 commit comments