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

Unable to reference a cdk.CfnParameter with Number type #2775

Closed
igilham opened this issue Jun 6, 2019 · 2 comments
Closed

Unable to reference a cdk.CfnParameter with Number type #2775

igilham opened this issue Jun 6, 2019 · 2 comments
Labels
@aws-cdk/core Related to core CDK functionality closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1

Comments

@igilham
Copy link
Contributor

igilham commented Jun 6, 2019

I'm using parameters for commonly editable fields in my company's deployment infrastructure. I've found that some fields in the SDK can accept parameters but some seem not to work.

One such case is when the target property is of type Number. This triggers a type mismatch in the Typescript compiler.

const lambdaHandlerParam = new cdk.CfnParameter(this, 'LambdaHandler', {
    type: 'String',
    default: 'index.handler',
    description: 'The name of the function (within your source code) that Lambda calls to start running your code.'
});

const lambdaRuntimeParam = new cdk.CfnParameter(this, 'LambdaRuntime', {
    type: 'String',
    default: 'nodejs10.x',
    description: 'The name of the AWS Lambda runtime.'
});

const lambdaTimeoutParam = new cdk.CfnParameter(this, 'LambdaTimeout', {
    type: 'Number',
    default: 60,
    description: 'The function execution time (in seconds) after which Lambda terminates the function.'
});

const placeholderBucketNameParam = new cdk.CfnParameter(this, 'FunctionPlaceholderBucketName', {
    type: 'String',
    default: 'placeholder-assets',
    description: 'The name of the bucket that contains the default function code'
});

const placeholderKeyParam = new cdk.CfnParameter(this, 'FunctionPlaceholderKey', {
    type: 'String',
    default: 'placeholder.zip',
    description: 'The S3 key in the FunctionPlaceholderBucket containing the placeholder function.'
});

new lambda.Function(this, "Lambdahandler", {
    runtime: new lambda.Runtime(lambdaRuntimeParam.ref),
    code: lambda.Code.cfnParameters({
        bucketNameParam: placeholderBucketNameParam,
        objectKeyParam: placeholderKeyParam
    }),
    handler: lambdaHandlerParam.ref,
    timeout: lambdaTimeoutParam.ref, // type error
    role: new iam.Role(this, 'FunctionRole', {
        assumedBy: new iam.ServicePrincipal('lambda')
    })
});

Here's the error on the line defining the timeout property:

error TS2322: Type 'string' is not assignable to type 'number | undefined'.

I haven't found a way to make this work. It looks like hard-coding to a numerical value is the only way supported by the type system at this time.

@igilham igilham added the gap label Jun 6, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 10, 2019

The right solution will be made more obvious in #2757, but for now what will work is lambdaTimoutParam.value.toNumber().

@NGL321 NGL321 added the needs-triage This issue or PR still needs to be triaged. label Jun 17, 2019
@SomayaB SomayaB added @aws-cdk/core Related to core CDK functionality feature-request A feature should be added or improved. and removed gap needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2019
@eladb eladb added the effort/medium Medium work item – several days of effort label Jan 23, 2020
@eladb eladb added the p1 label Aug 17, 2020
@eladb eladb assigned rix0rrr and unassigned eladb Aug 17, 2020
@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 17, 2022
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 closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

5 participants