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

NodejsFunction: Inconsistent SDK behavior with and without runtime specification #26459

Closed
rupe120 opened this issue Jul 21, 2023 · 4 comments · Fixed by #26664
Closed

NodejsFunction: Inconsistent SDK behavior with and without runtime specification #26459

rupe120 opened this issue Jul 21, 2023 · 4 comments · Fixed by #26664
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@rupe120
Copy link

rupe120 commented Jul 21, 2023

Describe the bug

The bundled SDK is different when a runtime is specified, as opposed to when it is left as default.

Expected Behavior

The behavior of the SDK when using the default runtime value is the expected behavior.

Current Behavior

If you try to use newer methods, like the QuickSight asset export methods an error saying that the classes are not constructors.

The following is what is produced when specifying runtime: lambda.Runtime.NODEJS_18_X

{
  "errorType": "TypeError",
  "errorMessage": "import_client_quicksight.StartAssetBundleExportJobCommand is not a constructor",
  "trace": [
    "TypeError: import_client_quicksight.StartAssetBundleExportJobCommand is not a constructor",
    "    at startQuicksightAssetExport (/var/task/index.js:47:30)",
    "    at Runtime.handler (/var/task/index.js:71:40)",
    "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1083:29)"
  ]
}

The following is what the same line produces without specifying a runtime value

{
  "errorType": "ValidationException",
  "errorMessage": "1 validation error detected: Value '[]' at 'resourceArns' failed to satisfy constraint: Member must have length greater than or equal to 1",
  "trace": [
    "ValidationException: 1 validation error detected: Value '[]' at 'resourceArns' failed to satisfy constraint: Member must have length greater than or equal to 1",
    "    at throwDefaultError (/var/task/index.js:9134:24)",
    "    at /var/task/index.js:9144:39",
    "    at de_StartAssetBundleExportJobCommandError (/var/task/index.js:30731:18)",
    "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
    "    at async /var/task/index.js:6077:24",
    "    at async /var/task/index.js:3722:22",
    "    at async /var/task/index.js:7329:42",
    "    at async /var/task/index.js:1186:26",
    "    at async startQuicksightAssetExport (/var/task/index.js:48531:41)",
    "    at async Runtime.handler (/var/task/index.js:48554:34)"
  ]
}

Each of these produce a Lambda using the NodeJs 18 runtime.

Reproduction Steps

Deploy the following repo into an account and run the quicksight-start-asset-export-w-runtime and quicksight-start-asset-export Lambdas.

https://github.com/rupe120/cdk-typescript-quicksight-sdk-test

Possible Solution

Unknown

Additional Information/Context

No response

CDK CLI Version

2.88.0

Framework Version

No response

Node.js Version

v18.16.1

OS

Windows 11 Enterprise build 22621.1702

Language

Typescript

Language Version

Typescript 5.1.6

Other information

No response

@rupe120 rupe120 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2023
@pahud
Copy link
Contributor

pahud commented Jul 21, 2023

I guess it's because the default runtime is node14 which does not come with SDK v3 yet provided in node18.

* @default Runtime.NODEJS_14_X
*/
readonly runtime?: lambda.Runtime;

And according to this, node18 runtime comes with SDK version 3.188.0 at this moment. If you need new methods that only available after 3.188.0 you probably have to bundle the latest aws js sdk into your lambda function with externals or nodeModules.

@pahud pahud added p2 effort/medium Medium work item – several days of effort response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2023
@peterwoodworth
Copy link
Contributor

Yes exactly @pahud, I think this is expected given the Lambda runtime defaults.

@peterwoodworth peterwoodworth added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jul 21, 2023
@rupe120
Copy link
Author

rupe120 commented Jul 22, 2023

Except they were both generated with NodeJs 18, and it's the one that I did not select NodeJs 18 explicitly and used the default behavior where the newer SDK call did work.

2023-07-21 20_30_28-quicksight-start-asset-export-w-runtime - Lambda — Mozilla Firefox
2023-07-21 20_31_37-quicksight-start-asset-export - Lambda — Mozilla Firefox

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 22, 2023
@mergify mergify bot closed this as completed in #26664 Aug 7, 2023
mergify bot pushed a commit that referenced this issue Aug 7, 2023
The docs for `NodeJsFunction` say `runtime` defaults to `NODEJS_14_X` but the code defaults to `lambda.Runtime.NODEJS_18_X` (on `function.ts:104`)

Closes #26459.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Aug 7, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants