@@ -408,3 +408,146 @@ test('Cannot create a SageMaker train task with both algorithm name and image na
408
408
} ) )
409
409
. toThrowError ( / M u s t d e f i n e e i t h e r a n a l g o r i t h m n a m e o r t r a i n i n g i m a g e U R I i n t h e a l g o r i t h m s p e c i f i c a t i o n / ) ;
410
410
} ) ;
411
+
412
+ test ( 'Cannot create a SageMaker train task with both algorithm name and image name defined' , ( ) => {
413
+
414
+ expect ( ( ) => new SageMakerCreateTrainingJob ( stack , 'SageMakerTrainingTask' , {
415
+ trainingJobName : 'myTrainJob' ,
416
+ algorithmSpecification : {
417
+ algorithmName : 'BlazingText' ,
418
+ trainingImage : tasks . DockerImage . fromJsonExpression ( sfn . JsonPath . stringAt ( '$.Training.imageName' ) ) ,
419
+ } ,
420
+ inputDataConfig : [
421
+ {
422
+ channelName : 'train' ,
423
+ dataSource : {
424
+ s3DataSource : {
425
+ s3DataType : tasks . S3DataType . S3_PREFIX ,
426
+ s3Location : tasks . S3Location . fromJsonExpression ( '$.S3Bucket' ) ,
427
+ } ,
428
+ } ,
429
+ } ,
430
+ ] ,
431
+ outputDataConfig : {
432
+ s3OutputLocation : tasks . S3Location . fromBucket ( s3 . Bucket . fromBucketName ( stack , 'Bucket' , 'mybucket' ) , 'myoutputpath/' ) ,
433
+ } ,
434
+ } ) )
435
+ . toThrowError ( / C a n n o t d e f i n e b o t h a n a l g o r i t h m n a m e a n d t r a i n i n g i m a g e U R I i n t h e a l g o r i t h m s p e c i f i c a t i o n / ) ;
436
+ } ) ;
437
+
438
+ test ( 'create a SageMaker train task with trainingImage' , ( ) => {
439
+
440
+ const task = new SageMakerCreateTrainingJob ( stack , 'SageMakerTrainingTask' , {
441
+ trainingJobName : 'myTrainJob' ,
442
+ algorithmSpecification : {
443
+ trainingImage : tasks . DockerImage . fromJsonExpression ( sfn . JsonPath . stringAt ( '$.Training.imageName' ) ) ,
444
+ } ,
445
+ inputDataConfig : [
446
+ {
447
+ channelName : 'train' ,
448
+ dataSource : {
449
+ s3DataSource : {
450
+ s3DataType : tasks . S3DataType . S3_PREFIX ,
451
+ s3Location : tasks . S3Location . fromJsonExpression ( '$.S3Bucket' ) ,
452
+ } ,
453
+ } ,
454
+ } ,
455
+ ] ,
456
+ outputDataConfig : {
457
+ s3OutputLocation : tasks . S3Location . fromBucket ( s3 . Bucket . fromBucketName ( stack , 'Bucket' , 'mybucket' ) , 'myoutputpath/' ) ,
458
+ } ,
459
+ } ) ;
460
+
461
+ // THEN
462
+ expect ( stack . resolve ( task . toStateJson ( ) ) ) . toMatchObject ( {
463
+ Parameters : {
464
+ AlgorithmSpecification : {
465
+ 'TrainingImage.$' : '$.Training.imageName' ,
466
+ 'TrainingInputMode' : 'File' ,
467
+ } ,
468
+ } ,
469
+ } ) ;
470
+ } ) ;
471
+
472
+ test ( 'create a SageMaker train task with image URI algorithmName' , ( ) => {
473
+
474
+ const task = new SageMakerCreateTrainingJob ( stack , 'SageMakerTrainingTask' , {
475
+ trainingJobName : 'myTrainJob' ,
476
+ algorithmSpecification : {
477
+ algorithmName : 'arn:aws:sagemaker:us-east-1:123456789012:algorithm/scikit-decision-trees' ,
478
+ } ,
479
+ inputDataConfig : [
480
+ {
481
+ channelName : 'train' ,
482
+ dataSource : {
483
+ s3DataSource : {
484
+ s3DataType : tasks . S3DataType . S3_PREFIX ,
485
+ s3Location : tasks . S3Location . fromJsonExpression ( '$.S3Bucket' ) ,
486
+ } ,
487
+ } ,
488
+ } ,
489
+ ] ,
490
+ outputDataConfig : {
491
+ s3OutputLocation : tasks . S3Location . fromBucket ( s3 . Bucket . fromBucketName ( stack , 'Bucket' , 'mybucket' ) , 'myoutputpath/' ) ,
492
+ } ,
493
+ } ) ;
494
+
495
+ // THEN
496
+ expect ( stack . resolve ( task . toStateJson ( ) ) ) . toMatchObject ( {
497
+ Parameters : {
498
+ AlgorithmSpecification : {
499
+ AlgorithmName : 'arn:aws:sagemaker:us-east-1:123456789012:algorithm/scikit-decision-trees' ,
500
+ } ,
501
+ } ,
502
+ } ) ;
503
+ } ) ;
504
+
505
+ test ( 'Cannot create a SageMaker train task when algorithmName length is 171 or more' , ( ) => {
506
+
507
+ expect ( ( ) => new SageMakerCreateTrainingJob ( stack , 'SageMakerTrainingTask' , {
508
+ trainingJobName : 'myTrainJob' ,
509
+ algorithmSpecification : {
510
+ algorithmName : 'a' . repeat ( 171 ) , // maximum length is 170
511
+ } ,
512
+ inputDataConfig : [
513
+ {
514
+ channelName : 'train' ,
515
+ dataSource : {
516
+ s3DataSource : {
517
+ s3DataType : tasks . S3DataType . S3_PREFIX ,
518
+ s3Location : tasks . S3Location . fromJsonExpression ( '$.S3Bucket' ) ,
519
+ } ,
520
+ } ,
521
+ } ,
522
+ ] ,
523
+ outputDataConfig : {
524
+ s3OutputLocation : tasks . S3Location . fromBucket ( s3 . Bucket . fromBucketName ( stack , 'Bucket' , 'mybucket' ) , 'myoutputpath/' ) ,
525
+ } ,
526
+ } ) )
527
+ . toThrowError ( / A l g o r i t h m n a m e l e n g t h m u s t b e b e t w e e n 1 a n d 1 7 0 , b u t g o t 1 7 1 / ) ;
528
+ } ) ;
529
+
530
+ test ( 'Cannot create a SageMaker train task with incorrect algorithmName' , ( ) => {
531
+
532
+ expect ( ( ) => new SageMakerCreateTrainingJob ( stack , 'SageMakerTrainingTask' , {
533
+ trainingJobName : 'myTrainJob' ,
534
+ algorithmSpecification : {
535
+ algorithmName : 'Blazing_Text' , // underscores are not allowed
536
+ } ,
537
+ inputDataConfig : [
538
+ {
539
+ channelName : 'train' ,
540
+ dataSource : {
541
+ s3DataSource : {
542
+ s3DataType : tasks . S3DataType . S3_PREFIX ,
543
+ s3Location : tasks . S3Location . fromJsonExpression ( '$.S3Bucket' ) ,
544
+ } ,
545
+ } ,
546
+ } ,
547
+ ] ,
548
+ outputDataConfig : {
549
+ s3OutputLocation : tasks . S3Location . fromBucket ( s3 . Bucket . fromBucketName ( stack , 'Bucket' , 'mybucket' ) , 'myoutputpath/' ) ,
550
+ } ,
551
+ } ) )
552
+ . toThrowError ( / E x p e c t e d a l g o r i t h m n a m e t o m a t c h p a t t e r n / ) ;
553
+ } ) ;
0 commit comments