-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lambda] 'valueAsString' works well with lazy resolution with lambda environment variables but the type 'Number' does not. #10228
Comments
It's because stringification happens in TypeScript without regard to whether it's a Token or not. Should have been |
@rix0rrr, can you please help me understand how should I be reading CfnParameter Number types for lambda functions, is there another way to read them. As a workaround, I am using the 'valueAsString' to get the parameters. |
Yes that will do it. |
What language are you using here? typescript or javascript? The type for the If you're on javascript, I believe it's up to you to ensure that you're performing the correct assignments. As noted, using |
The language for the runtime is typescript. @nija-at agree that the lambda environment variable is a string. Traditionally if I were to use CFN directly, I can define the parameter as a Number and have it Ref into the Lambda environment variables. This way I get appropriate parameter validation. In CDK if I can still use it as 'Number' and then be able to Ref the variable when assigning to Lambda still works fine. So there are two problems that I see
|
Thanks for the explanation @knihit. I see the problem. |
You can workaround this using |
CloudFormation allows for parameters of type 'Number' to be referenced, using the 'Ref' keyword, into properties that are of type 'String'. This will let customers now use CloudFormation maximum and minimum constraints on the number parameter type, and still use the resulting value where a string is expected. fixes #10228
…0422) CloudFormation allows for parameters of type 'Number' to be referenced, using the 'Ref' keyword, into properties that are of type 'String'. This will let customers now use CloudFormation maximum and minimum constraints on the number parameter type, and still use the resulting value in a property of string type. fixes #10228 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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
In another section of the code where I read the CfnParameter values
What did you expect to happen?
What actually happened?
Environment
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: