Skip to content

cdk import picking false changes for NodejsFunction #31999

@mrlikl

Description

@mrlikl

Describe the bug

When cdk import is comparing the current template with the synth template, it is picking false changes for NodejsFunction. For example, the below code

const rdsSchemaInitializerFunction = new _lambda_node.NodejsFunction(
      this,
      'rds-schema-initializer',
      {
        bundling: {
          minify: true,
          sourceMap: false,
          sourcesContent: false,
          target: 'ES2020'
        },
        runtime: _lambda.Runtime.NODEJS_18_X,
        entry: path.join(__dirname, 'lambda/index.ts')
      }
    )

During deploy time will have the template:

  rdsschemainitializerC99E4CA7:
    Type: AWS::Lambda::Function
    Properties:
      Code:
        S3Bucket:
          Fn::Sub: cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}
        S3Key: 336c1eb9382f4c0e4c84a0a0ef4cadd5d8df8a4921a98338abedd449e7cdaf12.zip
    Metadata:
      aws:cdk:path: CdktsStack/rds-schema-initializer/Resource
      aws:asset:path: asset.336c1eb9382f4c0e4c84a0a0ef4cadd5d8df8a4921a98338abedd449e7cdaf12
      aws:asset:is-bundled: true
      aws:asset:property: Code

and during synth of cdk import is having

"rdsschemainitializerC99E4CA7": {
            "Type": "AWS::Lambda::Function",
            "Properties": {
                "Code": {
                    "S3Bucket": {
                        "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
                    },
                    "S3Key": "eae9438382815864ae642eab331faf132022d63ea8625cc80b327506fbe57216.zip"
                }, 
            "Metadata": {
                "aws:cdk:path": "CdktsStack/rds-schema-initializer/Resource",
                "aws:asset:path": "/Users/muralikl/Downloads/nov3/cdkts",
                "aws:asset:is-bundled": true,
                "aws:asset:property": "Code"
            }
        },

There is no change in the code, but can see that the s3 key is changing for the time being and asset path is also pointing to the file path.

Performing cdk import with --force will ignore this issue and will successfully import the resources.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

cdk import to pick only the final template after synth and compare with the current deployed template

Current Behavior

cdk throwing a false positive change alongside import

Reproduction Steps

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as _lambda_node from 'aws-cdk-lib/aws-lambda-nodejs';
import * as _lambda from 'aws-cdk-lib/aws-lambda';
import * as s3 from 'aws-cdk-lib/aws-s3';
import path = require('path/posix')

export class CdktsStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const rdsSchemaInitializerFunction = new _lambda_node.NodejsFunction(
      this,
      'rds-schema-initializer',
      {
        bundling: {
          minify: true,
          sourceMap: false,
          sourcesContent: false,
          target: 'ES2020'
        },
        runtime: _lambda.Runtime.NODEJS_18_X,
        entry: path.join(__dirname, 'lambda/index.ts')
      }
    )
   // deploy the above code first and then add the below code to run cdk import
    new s3.Bucket(this, 'test', {
      removalPolicy: cdk.RemovalPolicy.DESTROY
    })
  }
}

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.165.0

Framework Version

No response

Node.js Version

20.17.0

OS

macos

Language

TypeScript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions