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

(triggers): deployments of trigger functions fail with TypeError [ERR_INVALID_ARG_TYPE]: The "msecs" argument must be of type number. Received type string #23407

Closed
cecheta opened this issue Dec 20, 2022 · 10 comments · Fixed by #23728 or #24435
Assignees
Labels
@aws-cdk/triggers Related to the triggers package bug This issue is a bug. effort/small Small work item – less than a day of effort management/tracking Issues that track a subject or multiple issues p0

Comments

@cecheta
Copy link
Contributor

cecheta commented Dec 20, 2022

Please add your +1 👍 to let us know you have encountered this
---

### Status: Resolved

This has been fixed as of CDK 2.61.1

### Overview:

Root cause: breaking change in #23062 caused the wrong type to be passed to CloudFormation (string where a number was expected). The integration test that was supposed to catch this somehow did not run, that is still being investigated.

When trying to invoke a function using the triggers module, an error occurs when the stack is deployed. InvocationType.EVENT invocation also does not work as the status code returned is not 200.

#### Complete Error Message:

submit response to cloudformation {
  Status: 'FAILED',
  Reason: `TypeError [ERR_INVALID_ARG_TYPE]: The "msecs" argument must be of type number. Received type string ('120000')\n` +
    '    at new NodeError (internal/errors.js:322:7)\n' +
    '    at validateNumber (internal/validators.js:129:11)\n' +
    '    at getTimerDuration (internal/timers.js:384:3)\n' +
    '    at ClientRequest.setTimeout (_http_client.js:865:11)\n' +
    '    at features.constructor.handleRequest (/var/runtime/node_modules/aws-sdk/lib/http/node.js:82:12)\n' +
    '    at executeSend (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:370:29)\n' +
    '    at Request.SEND (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:384:9)\n' +
    '    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:102:18)\n' +
    '    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)\n' +
    '    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:686:14)',
  StackId: 'arn:aws:cloudformation:us-east-1:***:stack/TestStack/83f77790-806c-11ed-8956-0a55d38b49ed',
  RequestId: '86a74312-347d-40c4-873a-09eed5b8eddd',
  PhysicalResourceId: 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED',
  LogicalResourceId: 'Trigger',
  NoEcho: undefined,
  Data: undefined
}

or

Error: Trigger handler failed with status code 202 at handler (/var/task/index.js:53:15) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Runtime.handler (/var/task/__entrypoint__.js:32:24) (RequestId: ab252a7a-e06b-4fcf-b2b4-f59b2dd88734)

### Solution: Revert #23062 until a more permanent fix is found.

Reproduction Steps

Deploy stack:

const func = new lambda.Function(stack, 'Function', {
  runtime: lambda.Runtime.NODEJS_18_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline('exports.handler = function() { console.log("hello"); };'),
});

const trigger = new triggers.Trigger(stack, 'Trigger', {
  handler: func,
  invocationType: triggers.InvocationType.EVENT,
});
@cecheta cecheta added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 20, 2022
@github-actions github-actions bot added the @aws-cdk/triggers Related to the triggers package label Dec 20, 2022
@peterwoodworth
Copy link
Contributor

Hey @cecheta, where are you finding the invocationType prop and the InvocationType enum? I can't find these in our API anywhere

@peterwoodworth peterwoodworth added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/small Small work item – less than a day of effort labels Dec 20, 2022
@cecheta
Copy link
Contributor Author

cecheta commented Dec 20, 2022

Hey @cecheta, where are you finding the invocationType prop and the InvocationType enum? I can't find these in our API anywhere

They were added in #23062

It's not in the latest release of the CDK yet, I ran into this issue when trying to create an integration test for an unrelated module

@peterwoodworth
Copy link
Contributor

Ah I see, thanks for being on top of this!

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 21, 2022
@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Dec 22, 2022
@tenjaa
Copy link
Contributor

tenjaa commented Dec 22, 2022

After merging cdk 2.56.0 today my deployment failed with that error message.

@kollmats
Copy link

I'm seeing this error too. I'm not explicitly passing any invocation type. My lambda does have a timout though. Downgrading to the version before 2.56.0 works.

@DerkSchooltink
Copy link
Contributor

Since I introduced the bug I will attempt to fix it :) I'm working on a PR

@DerkSchooltink
Copy link
Contributor

Not honouring the types specified to the custom resource seems to be related to aws-cloudformation/cloudformation-coverage-roadmap#1037

I'm not sure exactly what the way forward with that specific issue is. I will implement it as string and revert it back in the function handler, but perhaps in the future we can revert that change.

@tenjaa
Copy link
Contributor

tenjaa commented Jan 9, 2023

Is there any update on this as this stops us completely from updating cdk at the moment?

@DerkSchooltink
Copy link
Contributor

Holidays are over, I will have time for it soon :)

@comcalvi comcalvi changed the title (triggers): Unable to invoke function (triggers): deployments of trigger functions fail with TypeError [ERR_INVALID_ARG_TYPE]: The "msecs" argument must be of type number. Received type string Jan 19, 2023
@comcalvi comcalvi added p0 management/tracking Issues that track a subject or multiple issues and removed p2 labels Jan 20, 2023
@comcalvi comcalvi pinned this issue Jan 20, 2023
mergify bot pushed a commit to cdklabs/aws-cdk-notices that referenced this issue Jan 20, 2023
@mergify mergify bot closed this as completed in #23728 Jan 20, 2023
mergify bot pushed a commit that referenced this issue Jan 20, 2023
…23728)

Reverts #23062.

#23062 introduced #23407, which causes lambda functions that use triggers to fail to invoke with either this error

```
submit response to cloudformation {
  Status: 'FAILED',
  Reason: `TypeError [ERR_INVALID_ARG_TYPE]: The "msecs" argument must be of type number. Received type string ('120000')\n` +
    '    at new NodeError (internal/errors.js:322:7)\n' +
    '    at validateNumber (internal/validators.js:129:11)\n' +
    '    at getTimerDuration (internal/timers.js:384:3)\n' +
    '    at ClientRequest.setTimeout (_http_client.js:865:11)\n' +
    '    at features.constructor.handleRequest (/var/runtime/node_modules/aws-sdk/lib/http/node.js:82:12)\n' +
    '    at executeSend (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:370:29)\n' +
    '    at Request.SEND (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:384:9)\n' +
    '    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:102:18)\n' +
    '    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)\n' +
    '    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:686:14)',
  StackId: 'arn:aws:cloudformation:us-east-1:***:stack/TestStack/83f77790-806c-11ed-8956-0a55d38b49ed',
  RequestId: '86a74312-347d-40c4-873a-09eed5b8eddd',
  PhysicalResourceId: 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED',
  LogicalResourceId: 'Trigger',
  NoEcho: undefined,
  Data: undefined
}
```

or

```
Error: Trigger handler failed with status code 202 at handler (/var/task/index.js:53:15) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Runtime.handler (/var/task/__entrypoint__.js:32:24) (RequestId: ab252a7a-e06b-4fcf-b2b4-f59b2dd88734)
```

Reverting for now, since people are unable to upgrade. 

To unblock this revert, I'm disabling the integration test `dependencies-pnpm`, because when running it locally (and in this PR build) the logical ID of the version changes every run. This has been reproduced by others locally, so it's being disabled until we can resolve that issue.

Fixes #23407
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

comcalvi added a commit that referenced this issue Jan 20, 2023
…23728)

Reverts #23062.

#23062 introduced #23407, which causes lambda functions that use triggers to fail to invoke with either this error

```
submit response to cloudformation {
  Status: 'FAILED',
  Reason: `TypeError [ERR_INVALID_ARG_TYPE]: The "msecs" argument must be of type number. Received type string ('120000')\n` +
    '    at new NodeError (internal/errors.js:322:7)\n' +
    '    at validateNumber (internal/validators.js:129:11)\n' +
    '    at getTimerDuration (internal/timers.js:384:3)\n' +
    '    at ClientRequest.setTimeout (_http_client.js:865:11)\n' +
    '    at features.constructor.handleRequest (/var/runtime/node_modules/aws-sdk/lib/http/node.js:82:12)\n' +
    '    at executeSend (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:370:29)\n' +
    '    at Request.SEND (/var/runtime/node_modules/aws-sdk/lib/event_listeners.js:384:9)\n' +
    '    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:102:18)\n' +
    '    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)\n' +
    '    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:686:14)',
  StackId: 'arn:aws:cloudformation:us-east-1:***:stack/TestStack/83f77790-806c-11ed-8956-0a55d38b49ed',
  RequestId: '86a74312-347d-40c4-873a-09eed5b8eddd',
  PhysicalResourceId: 'AWSCDK::CustomResourceProviderFramework::CREATE_FAILED',
  LogicalResourceId: 'Trigger',
  NoEcho: undefined,
  Data: undefined
}
```

or

```
Error: Trigger handler failed with status code 202 at handler (/var/task/index.js:53:15) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Runtime.handler (/var/task/__entrypoint__.js:32:24) (RequestId: ab252a7a-e06b-4fcf-b2b4-f59b2dd88734)
```

Reverting for now, since people are unable to upgrade. 

To unblock this revert, I'm disabling the integration test `dependencies-pnpm`, because when running it locally (and in this PR build) the logical ID of the version changes every run. This has been reproduced by others locally, so it's being disabled until we can resolve that issue.

Fixes #23407
@vinayak-kukreja vinayak-kukreja unpinned this issue Feb 22, 2023
mergify bot pushed a commit that referenced this issue Apr 5, 2023
…timeouts (#24435)

Reopened PR from #23650 and #23788

And re-revert from #23062 ([v2.61.1](https://github.com/aws/aws-cdk/releases/tag/v2.61.1))

Implements #23058 and fixes #23407

Worked on comments from @TheRealAmazonKendra as well. Added an integration test scenario where a Lambda function will be triggered by a Trigger construct, send a message to an SQS queue, which will be consumed by the integration test assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment