Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.
I'm submitting a ...
What is the current behavior?
If the current behavior is a :beetle:bug:beetle:: Please provide the steps to reproduce
Create a CfnParameter with type 'Number' and a default value.
Use that value somewhere with parameter.valueAsNumber
Produces a value of -1.8881545897087546e+289
cosnt param = new CfnParameter(this, 'RedendtionPeriod', {
description: 'SQS redention period in seconds 60 - 1209600 [14400]',
type: 'Number',
default: 14400,
minValue: 60,
maxValue: 1209600,
constraintDescription: 'Must be between 60 and 1209600',
});
param.valueAsNumber // -1.8881545897087546e+289
What is the expected behavior (or behavior of feature suggested)?
Return the token for that value.
Please tell us about your environment:
So from what I understand this isnt a bug but how it is supposed to work. The number is an id of the token. However you are then unable to use this with any construct that takes a type number as typescript will pass type checking but you are providing it with the wrong number - not a reference.
I suspect this because I am abusing the API by mixing lower API Cfn constructs and the higher level constructs. However it seems missleading as valueAsString is usable
import { CfnParameter } from '@aws-cdk/core';
import { Queue, QueueEncryption } from '@aws-cdk/aws-sqs';
const redemptionPeriod = new CfnParameter(this, 'RedendtionPeriod', {
description: 'SQS redention period in seconds 60 - 1209600 [14400]',
type: 'Number',
default: 14400,
minValue: 60,
maxValue: 1209600,
constraintDescription: 'Must be between 60 and 1209600',
});
sqs = new Queue(this, 'MISQS', {
queueName: 'daily-journey-to-parquet-queue',
retentionPeriod: Duration.seconds(redentionPeriod.valueAsNumber), // This pass typechecking but will at best fail and at worst pass with the incorrect number.
deliveryDelay: Duration.seconds(0),
maxMessageSizeBytes: 1024,
receiveMessageWaitTime: Duration.seconds(20),
visibilityTimeout: Duration.seconds(60),
encryption: QueueEncryption.KMS,
});
Closing this as I dont believe its a bug its simply a limitation.
This is a bug, since the function valueAsNumber is suppose to return the value of the parameter not the reference as per the doc -

Can we please re-open this ?
@nagupta92 Ive reopened.
This is by design. Parameters are "late bound". Their values are only resolved during deployment and available only to CloudFormation. .valueAsNumber returns a token to the value as it will be resolved _during deployment_. It is impossible to know the value of the parameter during synthesis.
Closing.
Hey @eladb this is a bug specifically with SQS my above example with output the following error:
message retention period must be 60 seconds or more, but -1.8881545897087585e+289 was provided
Ill open a better bug report
Most helpful comment
@nagupta92 Ive reopened.