Skip to content

[@aws-cdk/aws-events] Schedule cannot be created from CfnParameter #9413

@alopix

Description

@alopix

When trying to use a parameter for the duration of a events Schedule, on synth, an error occurs: "Unable to perform time unit conversion on un-resolved token -1.8881545897087682e+289."

Specifying the duration for e.g. a Lambda timeout works, but not if the Duration is used in a Schedule.rate.

Reproduction Steps

import { Stack, App, Duration, CfnParameter } from '@aws-cdk/core';
import { Rule, Schedule } from '@aws-cdk/aws-events';

const invokeScheduleInMinutes = new CfnParameter(this, 'invokeScheduleInMinutes', {
      type: 'Number',
      description: 'The minutes between scheduled lambda invocations.'
});

new Rule(this, 'Rule', {
      ruleName: `cron`,
      schedule: Schedule.rate(Duration.minutes(invokeScheduleInMinutes.valueAsNumber))
});

Error Log

…/node_modules/@aws-cdk/core/lib/duration.ts:289
    throw new Error(`Unable to perform time unit conversion on un-resolved token ${amount}.`);
          ^
Error: Unable to perform time unit conversion on un-resolved token -1.8881545897087682e+289.
    at convert (…/node_modules/@aws-cdk/core/lib/duration.ts:289:11)
    at Duration.toSeconds (…node_modules/@aws-cdk/core/lib/duration.ts:127:12)
    at Function.rate (…/node_modules/@aws-cdk/aws-events/lib/schedule.ts:20:18)
    at new AppStack (…/infrastructure/stacks/src/AppStack.ts:47:26)
    at Object.<anonymous> (…/infrastructure/stacks/src/app.ts:21:1)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Module.m._compile (…/node_modules/ts-node/src/index.ts:858:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Object.require.extensions.<computed> [as .ts] (…/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:1002:32)

Environment

  • CLI Version : 1.56.0
  • Framework Version: 1.56.0
  • Node.js Version: v12.16.1
  • OS : macOS
  • Language (Version): TypeScript 3.9.7

Other


This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch Eventseffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions