Skip to content
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

Parameter valueAsNumber not returning correct number. #3448

Closed
4 tasks
amwill04 opened this issue Jul 26, 2019 · 7 comments
Closed
4 tasks

Parameter valueAsNumber not returning correct number. #3448

amwill04 opened this issue Jul 26, 2019 · 7 comments
Assignees
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@amwill04
Copy link

amwill04 commented Jul 26, 2019

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 ...

    • [X ] 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a 🪲bug🪲: 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:

    • CDK CLI Version: 1.2.0
    • Module Version: 1.2.0
    • OS: OSX Mojave
    • Language: Typescript
@amwill04 amwill04 added the needs-triage This issue or PR still needs to be triaged. label Jul 26, 2019
@amwill04
Copy link
Author

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,
        });

@amwill04
Copy link
Author

Closing this as I dont believe its a bug its simply a limitation.

@nagupta92
Copy link

nagupta92 commented Dec 17, 2019

This is a bug, since the function valueAsNumber is suppose to return the value of the parameter not the reference as per the doc -
image

Can we please re-open this ?

@amwill04
Copy link
Author

@nagupta92 Ive reopened.

@amwill04 amwill04 reopened this Dec 17, 2019
@SomayaB SomayaB added bug This issue is a bug. @aws-cdk/core Related to core CDK functionality labels Dec 18, 2019
@eladb
Copy link
Contributor

eladb commented Dec 22, 2019

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.

@eladb eladb closed this as completed Dec 22, 2019
@amwill04
Copy link
Author

amwill04 commented Apr 1, 2020

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

@amwill04
Copy link
Author

amwill04 commented Apr 1, 2020

Ill open a better bug report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants