@@ -5046,27 +5046,19 @@ describe('Lambda Function log group behavior', () => {
50465046} ) ;
50475047
50485048describe ( 'telemetry metadata' , ( ) => {
5049- let getPrototypeOfSpy : jest . SpyInstance ;
5049+ it ( 'redaction happens when feature flag is enabled' , ( ) => {
5050+ const app = new cdk . App ( ) ;
5051+ app . node . setContext ( cxapi . ENABLE_ADDITIONAL_METADATA_COLLECTION , true ) ;
5052+ const stack = new cdk . Stack ( app ) ;
50505053
5051- beforeEach ( ( ) => {
50525054 const mockConstructor = {
50535055 [ JSII_RUNTIME_SYMBOL ] : {
50545056 fqn : 'aws-cdk-lib.aws-lambda.Function' ,
50555057 } ,
50565058 } ;
5057- getPrototypeOfSpy = jest . spyOn ( Object , 'getPrototypeOf' ) . mockReturnValue ( {
5059+ jest . spyOn ( Object , 'getPrototypeOf' ) . mockReturnValue ( {
50585060 constructor : mockConstructor ,
50595061 } ) ;
5060- } ) ;
5061-
5062- afterEach ( ( ) => {
5063- getPrototypeOfSpy . mockRestore ( ) ;
5064- } ) ;
5065-
5066- it ( 'redaction happens when feature flag is enabled' , ( ) => {
5067- const app = new cdk . App ( ) ;
5068- app . node . setContext ( cxapi . ENABLE_ADDITIONAL_METADATA_COLLECTION , true ) ;
5069- const stack = new cdk . Stack ( app ) ;
50705062
50715063 const fn = new lambda . Function ( stack , 'Lambda' , {
50725064 code : lambda . Code . fromInline ( 'foo' ) ,
@@ -5097,6 +5089,15 @@ describe('telemetry metadata', () => {
50975089 app . node . setContext ( cxapi . ENABLE_ADDITIONAL_METADATA_COLLECTION , false ) ;
50985090 const stack = new cdk . Stack ( app ) ;
50995091
5092+ const mockConstructor = {
5093+ [ JSII_RUNTIME_SYMBOL ] : {
5094+ fqn : 'aws-cdk-lib.aws-lambda.Function' ,
5095+ } ,
5096+ } ;
5097+ jest . spyOn ( Object , 'getPrototypeOf' ) . mockReturnValue ( {
5098+ constructor : mockConstructor ,
5099+ } ) ;
5100+
51005101 const fn = new lambda . Function ( stack , 'Lambda' , {
51015102 code : lambda . Code . fromInline ( 'foo' ) ,
51025103 handler : 'index.handler' ,
@@ -5106,148 +5107,6 @@ describe('telemetry metadata', () => {
51065107 expect ( fn . node . metadata ) . toStrictEqual ( [ ] ) ;
51075108 } ) ;
51085109} ) ;
5109- describe ( 'L1 Relationships' , ( ) => {
5110- it ( 'simple union' , ( ) => {
5111- const stack = new cdk . Stack ( ) ;
5112- const role = new iam . Role ( stack , 'SomeRole' , {
5113- assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
5114- } ) ;
5115- new lambda . CfnFunction ( stack , 'MyLambda' , {
5116- code : { zipFile : 'foo' } ,
5117- role : role , // Simple Union
5118- } ) ;
5119- Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::Function' , {
5120- Properties : {
5121- Role : { 'Fn::GetAtt' : [ 'SomeRole6DDC54DD' , 'Arn' ] } ,
5122- } ,
5123- } ) ;
5124- } ) ;
5125-
5126- it ( 'array of unions' , ( ) => {
5127- const stack = new cdk . Stack ( ) ;
5128- const role = new iam . Role ( stack , 'SomeRole' , {
5129- assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
5130- } ) ;
5131- const layer1 = new lambda . LayerVersion ( stack , 'LayerVersion1' , {
5132- code : lambda . Code . fromAsset ( path . join ( __dirname , 'my-lambda-handler' ) ) ,
5133- compatibleRuntimes : [ lambda . Runtime . PYTHON_3_13 ] ,
5134- } ) ;
5135- const layer2 = new lambda . LayerVersion ( stack , 'LayerVersion2' , {
5136- code : lambda . Code . fromAsset ( path . join ( __dirname , 'my-lambda-handler' ) ) ,
5137- compatibleRuntimes : [ lambda . Runtime . PYTHON_3_13 ] ,
5138- } ) ;
5139- new lambda . CfnFunction ( stack , 'MyLambda' , {
5140- code : { zipFile : 'foo' } ,
5141- role : role ,
5142- layers : [ layer1 , layer2 ] , // Array of Unions
5143- } ) ;
5144- Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::Function' , {
5145- Properties : {
5146- Role : { 'Fn::GetAtt' : [ 'SomeRole6DDC54DD' , 'Arn' ] } ,
5147- Layers : [ { Ref : 'LayerVersion139D4D7A8' } , { Ref : 'LayerVersion23E5F3CEA' } ] ,
5148- } ,
5149- } ) ;
5150- } ) ;
5151-
5152- it ( 'nested union' , ( ) => {
5153- const stack = new cdk . Stack ( ) ;
5154- const role = new iam . Role ( stack , 'SomeRole' , {
5155- assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
5156- } ) ;
5157- const bucket = new s3 . Bucket ( stack , 'MyBucket' ) ;
5158-
5159- new lambda . CfnFunction ( stack , 'MyLambda' , {
5160- code : {
5161- s3Bucket : bucket , // Nested union
5162- } ,
5163- role : role ,
5164- } ) ;
5165- Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::Function' , {
5166- Properties : {
5167- Role : { 'Fn::GetAtt' : [ 'SomeRole6DDC54DD' , 'Arn' ] } ,
5168- Code : { S3Bucket : { Ref : 'MyBucketF68F3FF0' } } ,
5169- } ,
5170- } ) ;
5171- } ) ;
5172-
5173- it ( 'deeply nested union' , ( ) => {
5174- const stack = new cdk . Stack ( ) ;
5175- const topic = new sns . CfnTopic ( stack , 'Topic' ) ;
5176-
5177- new lambda . CfnEventInvokeConfig ( stack , 'EventConfig' , {
5178- functionName : 'myFunction' ,
5179- qualifier : '$LATEST' ,
5180- destinationConfig : {
5181- onFailure : {
5182- destination : topic , // Deeply nested: destinationConfig -> onFailure -> destination (union)
5183- } ,
5184- } ,
5185- } ) ;
5186- Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::EventInvokeConfig' , {
5187- Properties : {
5188- DestinationConfig : {
5189- OnFailure : {
5190- Destination : { Ref : 'Topic' } ,
5191- } ,
5192- } ,
5193- } ,
5194- } ) ;
5195- } ) ;
5196-
5197- it ( 'nested array of unions' , ( ) => {
5198- const stack = new cdk . Stack ( ) ;
5199- const role = new iam . Role ( stack , 'SomeRole' , {
5200- assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
5201- } ) ;
5202- const securityGroup = new ec2 . SecurityGroup ( stack , 'SG' , {
5203- vpc : new ec2 . Vpc ( stack , 'VPC' ) ,
5204- } ) ;
5205- new lambda . CfnFunction ( stack , 'MyLambda' , {
5206- code : { zipFile : 'foo' } ,
5207- role : role ,
5208- vpcConfig : {
5209- securityGroupIds : [ securityGroup ] , // Nested array of union
5210- } ,
5211- } ) ;
5212- Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::Function' , {
5213- Properties : {
5214- Role : { 'Fn::GetAtt' : [ 'SomeRole6DDC54DD' , 'Arn' ] } ,
5215- VpcConfig : {
5216- SecurityGroupIds : [ { 'Fn::GetAtt' : [ 'SGADB53937' , 'GroupId' ] } ] ,
5217- } ,
5218- } ,
5219- } ) ;
5220- } ) ;
5221-
5222- it ( 'tokens should be passed as is' , ( ) => {
5223- const stack = new cdk . Stack ( ) ;
5224- const role = new iam . Role ( stack , 'SomeRole' , {
5225- assumedBy : new iam . ServicePrincipal ( 'lambda.amazonaws.com' ) ,
5226- } ) ;
5227- const bucket = new s3 . Bucket ( stack , 'MyBucket' ) ;
5228-
5229- const codeToken = cdk . Token . asAny ( {
5230- resolve : ( ) => ( { s3Bucket : bucket . bucketName } ) ,
5231- } ) ;
5232-
5233- const fsConfigToken = cdk . Token . asAny ( {
5234- resolve : ( ) => ( [ { arn : 'TestArn' , localMountPath : '/mnt' } ] ) ,
5235- } ) ;
5236-
5237- new lambda . CfnFunction ( stack , 'MyLambda' , {
5238- code : codeToken ,
5239- role : role ,
5240- fileSystemConfigs : fsConfigToken ,
5241- } ) ;
5242- Template . fromStack ( stack ) . hasResource ( 'AWS::Lambda::Function' , {
5243- Properties : {
5244- Role : { 'Fn::GetAtt' : [ 'SomeRole6DDC54DD' , 'Arn' ] } ,
5245- Code : { S3Bucket : { Ref : 'MyBucketF68F3FF0' } } ,
5246- FileSystemConfigs : [ { Arn : 'TestArn' , LocalMountPath : '/mnt' } ] ,
5247- } ,
5248- } ) ;
5249- } ) ;
5250- } ) ;
52515110
52525111function newTestLambda ( scope : constructs . Construct ) {
52535112 return new lambda . Function ( scope , 'MyLambda' , {
0 commit comments