Skip to content

[lambda] 'valueAsString' works well with lazy resolution with lambda environment variables but the type 'Number' does not. #10228

@knihit

Description

@knihit

I am using CfnParameter to read various parameters. One of the parameter types is a 'Number' with min value 1 and max value as 100. This value of this parameter is then passed as the lambda environment key value pairs. When I use 'valueAsNumber' method in conjunction with the lambda environment variables, cdk synth does not synthesize this code for lazy resolution through 'Ref'. It rather assigns a value to the lambda environment variable during synth process. 'valueAsString' works well with lazy resolution with lambda environment variables but the type 'Number' does not.

Reproduction Steps

    const numberOfTopics = new CfnParameter(this, 'NumberOfTopics', {
        type: 'Number',
        default: 10,
        minValue: 1,
        maxValue: 100,
        description: 'The number of topics to be discovered by Topic analysis. The min value is 1 and maximum value is 100'
    });

In another section of the code where I read the CfnParameter values

        lambdaFunctionProps: {
            runtime: Runtime.NODEJS_12_X,
            handler: 'index.handler',
            code: Code.fromAsset(`${__dirname}/../../lambda/wf-submit-topic-model`),
            environment: {
                INGESTION_WINDOW: props.ingestionWindow,
                RAW_BUCKET_FEED: props.rawBucket.bucketName,
                **NUMBER_OF_TOPICS: props.numberofTopics,**
                STACK_NAME: props.stackName
            },
            timeout: Duration.minutes(5),
            memorySize: 512
        },

What did you expect to happen?

    "NUMBER_OF_TOPICS": {
      "Ref": "NumberOfTopics"
    },

What actually happened?

Environment

  • CLI Version: aws-cli/2.0.44 Python/3.8.5 Darwin/19.6.0 source/x86_64
  • Framework Version: 1.62.0
  • Node.js Version: 14.9.0
  • OS: MacOS
  • Language (Version): 4.0.2

This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions