@@ -12,6 +12,7 @@ import * as sns from '@aws-cdk/aws-sns';
12
12
import * as sqs from '@aws-cdk/aws-sqs' ;
13
13
import { testDeprecated } from '@aws-cdk/cdk-build-tools' ;
14
14
import * as cdk from '@aws-cdk/core' ;
15
+ import { Intrinsic , Token } from '@aws-cdk/core' ;
15
16
import * as constructs from 'constructs' ;
16
17
import * as _ from 'lodash' ;
17
18
import * as lambda from '../lib' ;
@@ -2404,6 +2405,45 @@ describe('function', () => {
2404
2405
} ) ;
2405
2406
expect ( fn . architecture ?. name ) . toEqual ( 'arm64' ) ;
2406
2407
} ) ;
2408
+
2409
+ test ( 'Error when function name is longer than 64 chars' , ( ) => {
2410
+ const stack = new cdk . Stack ( ) ;
2411
+ expect ( ( ) => new lambda . Function ( stack , 'MyFunction' , {
2412
+ code : lambda . Code . fromInline ( 'foo' ) ,
2413
+ runtime : lambda . Runtime . NODEJS_14_X ,
2414
+ handler : 'index.handler' ,
2415
+ functionName : 'a' . repeat ( 65 ) ,
2416
+ } ) ) . toThrow ( / F u n c t i o n n a m e c a n n o t b e l o n g e r t h a n 6 4 c h a r a c t e r s / ) ;
2417
+ } ) ;
2418
+
2419
+ test ( 'Error when function name contains invalid characters' , ( ) => {
2420
+ const stack = new cdk . Stack ( ) ;
2421
+ [ ' ' , '\n' , '\r' , '[' , ']' , '<' , '>' , '$' ] . forEach ( invalidChar => {
2422
+ expect ( ( ) => {
2423
+ new lambda . Function ( stack , `foo${ invalidChar } ` , {
2424
+ code : new lambda . InlineCode ( 'foo' ) ,
2425
+ handler : 'index.handler' ,
2426
+ runtime : lambda . Runtime . NODEJS_14_X ,
2427
+ functionName : `foo${ invalidChar } ` ,
2428
+ } ) ;
2429
+ } ) . toThrow ( / c a n c o n t a i n o n l y l e t t e r s , n u m b e r s , h y p h e n s , o r u n d e r s c o r e s w i t h n o s p a c e s ./ ) ;
2430
+ } ) ;
2431
+ } ) ;
2432
+
2433
+ test ( 'No error when function name is Tokenized and Unresolved' , ( ) => {
2434
+ const stack = new cdk . Stack ( ) ;
2435
+ expect ( ( ) => {
2436
+ const realFunctionName = 'a' . repeat ( 141 ) ;
2437
+ const tokenizedFunctionName = Token . asString ( new Intrinsic ( realFunctionName ) ) ;
2438
+
2439
+ new lambda . Function ( stack , 'foo' , {
2440
+ code : new lambda . InlineCode ( 'foo' ) ,
2441
+ handler : 'index.handler' ,
2442
+ runtime : lambda . Runtime . NODEJS_14_X ,
2443
+ functionName : tokenizedFunctionName ,
2444
+ } ) ;
2445
+ } ) . not . toThrow ( ) ;
2446
+ } ) ;
2407
2447
} ) ;
2408
2448
2409
2449
function newTestLambda ( scope : constructs . Construct ) {
0 commit comments