Skip to content

[Core]: addPropertyOverride not producing correct result after upgrade #19971

@Rohit-nagbhidkar

Description

@Rohit-nagbhidkar

Describe the bug

When adding a condition on the LambdaFunctionArn to be attached to Custom::S3BucketNotifications resource, cdk is appending the If condition rather than replacing it.
This was working with version 1.100.0, but due to a new requirement we bumped up the version to 1.152.0
PFB for code snippet

      config.uploadTempBucket.addObjectCreatedNotification(new LambdaDestination(config.s3DocUploadLambda));
       const conditionForDT = new CfnCondition(scope, 'EnvCheckDT', {
           expression: Fn.conditionEquals(config.envName, 'DT')
       });
       const fileSecurityScanLambda = Function.fromFunctionArn(scope, 'FileSecurityScan-Lambda', config.fileScanLambdaArnString);
       const applicableFunction = Fn.conditionIf(conditionForDT.logicalId, config.s3DocUploadLambda.functionArn, fileSecurityScanLambda.functionArn).toString();
       let cfnResource = Stack.of(scope).node.findAll(ConstructOrder.POSTORDER).find(child => child instanceof CfnResource && child.cfnResourceType == 'Custom::S3BucketNotifications') as CfnResource;
//issue in following code
       cfnResource.addPropertyOverride('NotificationConfiguration.LambdaFunctionConfigurations.0.LambdaFunctionArn',
           applicableFunction
       );

Expected Behavior

in earlier version 1.100.0 the cfn template produced from the code is as below

      NotificationConfiguration:
        LambdaFunctionConfigurations:
          - Events:
              - s3:ObjectCreated:*
            LambdaFunctionArn:
              Fn::If:
                - EnvCheckDT
                - Fn::GetAtt:
                    - AegonDocumentUploadv11F49C644
                    - Arn
                - Ref: FileScanLambdaArn

Current Behavior

after version upgrade to 1.152.0 the cfn template produced from the code is as below


      NotificationConfiguration:
        LambdaFunctionConfigurations:
          - Events:
              - s3:ObjectCreated:*
            LambdaFunctionArn:
          Fn::GetAtt:
                - AegonDocumentUploadv11F49C644
                - Arn
              Fn::If:
                - EnvCheckDT
                - Fn::GetAtt:
                    - AegonDocumentUploadv11F49C644
                    - Arn
                - Ref: FileScanLambdaArn
   

Code is getting synthesized without errors
but while deployment it's giving following error.

Received response status [FAILED] from custom resource. Message returned: Error: Parameter validation failed: Invalid type for parameter NotificationConfiguration.LambdaFunctionConfigurations[0].LambdaFunctionArn, value: {'Fn::GetAtt': ['DocumentUploadv11F49C644', 'Arn'], 'Fn::If': ['EnvCheckDT', 'arn:aws:lambda:ap-south-1:xxx:function:document-upload-v1-DT', 'arn:aws:lambda:ap-south-1:xxx:function:document-upload-v1-DT']}, type: <class 'dict'>, valid types: <class 'str'>.

Kindly look into this

Reproduction Steps

try writing similar kind of code to reproduce

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

1.152.0 (build 9487b39)

Framework Version

No response

Node.js Version

14.16.1

OS

Windows 10

Language

Typescript

Language Version

4.1.6

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/smallSmall work item – less than a day of effortp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions