@@ -9,6 +9,7 @@ import { ArnPrincipal, Role } from 'aws-cdk-lib/aws-iam';
9
9
import * as logs from 'aws-cdk-lib/aws-logs' ;
10
10
import { Secret } from 'aws-cdk-lib/aws-secretsmanager' ;
11
11
import { Size , Stack } from 'aws-cdk-lib' ;
12
+ import * as cdk from 'aws-cdk-lib' ;
12
13
import { EcsContainerDefinitionProps , EcsEc2ContainerDefinition , EcsFargateContainerDefinition , EcsJobDefinition , EcsVolume , IEcsEc2ContainerDefinition , LinuxParameters , UlimitName } from '../lib' ;
13
14
import { CfnJobDefinitionProps } from 'aws-cdk-lib/aws-batch' ;
14
15
import { capitalizePropertyNames } from './utils' ;
@@ -792,4 +793,74 @@ describe('Fargate containers', () => {
792
793
} ,
793
794
} ) ;
794
795
} ) ;
796
+
797
+ test ( 'can set ephemeralStorageSize' , ( ) => {
798
+ // WHEN
799
+ new EcsJobDefinition ( stack , 'ECSJobDefn' , {
800
+ container : new EcsFargateContainerDefinition ( stack , 'EcsFargateContainer' , {
801
+ ...defaultContainerProps ,
802
+ fargatePlatformVersion : ecs . FargatePlatformVersion . LATEST ,
803
+ ephemeralStorageSize : Size . gibibytes ( 100 ) ,
804
+ } ) ,
805
+ } ) ;
806
+
807
+ // THEN
808
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Batch::JobDefinition' , {
809
+ ...pascalCaseExpectedProps ,
810
+ ContainerProperties : {
811
+ ...pascalCaseExpectedProps . ContainerProperties ,
812
+ ExecutionRoleArn : {
813
+ 'Fn::GetAtt' : [ 'EcsFargateContainerExecutionRole3286EAFE' , 'Arn' ] ,
814
+ } ,
815
+ EphemeralStorage : {
816
+ SizeInGiB : Size . gibibytes ( 100 ) . toGibibytes ( ) ,
817
+ } ,
818
+ } ,
819
+ } ) ;
820
+ } ) ;
821
+
822
+ test ( 'can set ephemeralStorageSize as token' , ( ) => {
823
+ const ephemeralStorageValue : number = cdk . Token . asNumber ( 150 ) ;
824
+
825
+ // WHEN
826
+ new EcsJobDefinition ( stack , 'ECSJobDefn' , {
827
+ container : new EcsFargateContainerDefinition ( stack , 'EcsFargateContainer' , {
828
+ ...defaultContainerProps ,
829
+ fargatePlatformVersion : ecs . FargatePlatformVersion . LATEST ,
830
+ ephemeralStorageSize : Size . gibibytes ( ephemeralStorageValue ) ,
831
+ } ) ,
832
+ } ) ;
833
+
834
+ // THEN
835
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Batch::JobDefinition' , {
836
+ ...pascalCaseExpectedProps ,
837
+ ContainerProperties : {
838
+ ...pascalCaseExpectedProps . ContainerProperties ,
839
+ ExecutionRoleArn : {
840
+ 'Fn::GetAtt' : [ 'EcsFargateContainerExecutionRole3286EAFE' , 'Arn' ] ,
841
+ } ,
842
+ EphemeralStorage : {
843
+ SizeInGiB : Size . gibibytes ( 150 ) . toGibibytes ( ) ,
844
+ } ,
845
+ } ,
846
+ } ) ;
847
+ } ) ;
848
+
849
+ test ( 'ephemeralStorageSize throws error when out of range' , ( ) => {
850
+ expect ( ( ) => new EcsJobDefinition ( stack , 'ECSJobDefn' , {
851
+ container : new EcsFargateContainerDefinition ( stack , 'EcsFargateContainer' , {
852
+ ...defaultContainerProps ,
853
+ fargatePlatformVersion : ecs . FargatePlatformVersion . LATEST ,
854
+ ephemeralStorageSize : Size . gibibytes ( 19 ) ,
855
+ } ) ,
856
+ } ) ) . toThrow ( "ECS Fargate container 'EcsFargateContainer' specifies 'ephemeralStorageSize' at 19 < 21 GB" ) ;
857
+
858
+ expect ( ( ) => new EcsJobDefinition ( stack , 'ECSJobDefn2' , {
859
+ container : new EcsFargateContainerDefinition ( stack , 'EcsFargateContainer2' , {
860
+ ...defaultContainerProps ,
861
+ fargatePlatformVersion : ecs . FargatePlatformVersion . LATEST ,
862
+ ephemeralStorageSize : Size . gibibytes ( 201 ) ,
863
+ } ) ,
864
+ } ) ) . toThrow ( "ECS Fargate container 'EcsFargateContainer2' specifies 'ephemeralStorageSize' at 201 > 200 GB" ) ;
865
+ } ) ;
795
866
} ) ;
0 commit comments