@@ -2923,6 +2923,99 @@ describe('function', () => {
2923
2923
} ) ;
2924
2924
} ) ;
2925
2925
2926
+ test ( 'validate localMountPath format when mounting efs' , ( ) => {
2927
+ // GIVEN
2928
+ const stack = new cdk . Stack ( ) ;
2929
+ const vpc = new ec2 . Vpc ( stack , 'Vpc' , {
2930
+ maxAzs : 3 ,
2931
+ natGateways : 1 ,
2932
+ } ) ;
2933
+ const securityGroup = new ec2 . SecurityGroup ( stack , 'LambdaSG' , {
2934
+ vpc,
2935
+ allowAllOutbound : false ,
2936
+ } ) ;
2937
+
2938
+ const fs = new efs . FileSystem ( stack , 'Efs' , {
2939
+ vpc,
2940
+ } ) ;
2941
+ const accessPoint = fs . addAccessPoint ( 'AccessPoint' ) ;
2942
+
2943
+ // THEN
2944
+ expect ( ( ) => {
2945
+ new lambda . Function ( stack , 'MyFunction' , {
2946
+ vpc,
2947
+ handler : 'foo' ,
2948
+ securityGroups : [ securityGroup ] ,
2949
+ runtime : lambda . Runtime . NODEJS_LATEST ,
2950
+ code : lambda . Code . fromAsset ( path . join ( __dirname , 'handler.zip' ) ) ,
2951
+ filesystem : lambda . FileSystem . fromEfsAccessPoint ( accessPoint , '/not-mnt/foo-bar' ) ,
2952
+ } ) ;
2953
+ } ) . toThrow ( 'Local mount path should match with ^/mnt/[a-zA-Z0-9-_.]+$ but given /not-mnt/foo-bar' ) ;
2954
+ } ) ;
2955
+
2956
+ test ( 'validate localMountPath length when mounting efs' , ( ) => {
2957
+ // GIVEN
2958
+ const stack = new cdk . Stack ( ) ;
2959
+ const vpc = new ec2 . Vpc ( stack , 'Vpc' , {
2960
+ maxAzs : 3 ,
2961
+ natGateways : 1 ,
2962
+ } ) ;
2963
+ const securityGroup = new ec2 . SecurityGroup ( stack , 'LambdaSG' , {
2964
+ vpc,
2965
+ allowAllOutbound : false ,
2966
+ } ) ;
2967
+
2968
+ const fs = new efs . FileSystem ( stack , 'Efs' , {
2969
+ vpc,
2970
+ } ) ;
2971
+ const accessPoint = fs . addAccessPoint ( 'AccessPoint' ) ;
2972
+
2973
+ // THEN
2974
+ expect ( ( ) => {
2975
+ new lambda . Function ( stack , 'MyFunction' , {
2976
+ vpc,
2977
+ handler : 'foo' ,
2978
+ securityGroups : [ securityGroup ] ,
2979
+ runtime : lambda . Runtime . NODEJS_LATEST ,
2980
+ code : lambda . Code . fromAsset ( path . join ( __dirname , 'handler.zip' ) ) ,
2981
+ filesystem : lambda . FileSystem . fromEfsAccessPoint ( accessPoint , `/mnt/${ 'a' . repeat ( 160 ) } ` ) ,
2982
+ } ) ;
2983
+ } ) . toThrow ( 'Local mount path can not be longer than 160 characters but has 165 characters' ) ;
2984
+ } ) ;
2985
+
2986
+ test ( 'No error when local mount path is Tokenized and Unresolved' , ( ) => {
2987
+ // GIVEN
2988
+ const realLocalMountPath = '/not-mnt/foo-bar' ;
2989
+ const tokenizedLocalMountPath = cdk . Token . asString ( new cdk . Intrinsic ( realLocalMountPath ) ) ;
2990
+
2991
+ const stack = new cdk . Stack ( ) ;
2992
+ const vpc = new ec2 . Vpc ( stack , 'Vpc' , {
2993
+ maxAzs : 3 ,
2994
+ natGateways : 1 ,
2995
+ } ) ;
2996
+ const securityGroup = new ec2 . SecurityGroup ( stack , 'LambdaSG' , {
2997
+ vpc,
2998
+ allowAllOutbound : false ,
2999
+ } ) ;
3000
+
3001
+ const fs = new efs . FileSystem ( stack , 'Efs' , {
3002
+ vpc,
3003
+ } ) ;
3004
+ const accessPoint = fs . addAccessPoint ( 'AccessPoint' ) ;
3005
+
3006
+ // THEN
3007
+ expect ( ( ) => {
3008
+ new lambda . Function ( stack , 'MyFunction' , {
3009
+ vpc,
3010
+ handler : 'foo' ,
3011
+ securityGroups : [ securityGroup ] ,
3012
+ runtime : lambda . Runtime . NODEJS_LATEST ,
3013
+ code : lambda . Code . fromAsset ( path . join ( __dirname , 'handler.zip' ) ) ,
3014
+ filesystem : lambda . FileSystem . fromEfsAccessPoint ( accessPoint , tokenizedLocalMountPath ) ,
3015
+ } ) ;
3016
+ } ) . not . toThrow ( ) ;
3017
+ } ) ;
3018
+
2926
3019
test ( 'correct security group is created when deployed in separate stacks' , ( ) => {
2927
3020
const app = new cdk . App ( ) ;
2928
3021
0 commit comments