aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 821 forks source link

Amplify mock function uses mysterious version of NodeJS #10940

Open dmost714 opened 2 years ago

dmost714 commented 2 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v16.16.0

Amplify CLI Version

9.2.1

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

Yes. Notably, I added/updated LambdaFunction properties:

        "Runtime": "nodejs16.x",
        "Architectures": [
          "arm64"
        ],
        "Layers": [],
        "MemorySize": 256,
        "Timeout": 300

Amplify Categories

function

Amplify Commands

Not applicable

Describe the bug

When I mock functions, they're using NodeJS v14.18.1. From what I can tell, I don't even have that version installed.

amplify mock function myAppMylambda --event src/event.json

Verified by console logging the node version within the Lambda:

import { version } from 'node:process'
console.log(`NodeJS Version: ${version}`)

Expected behavior

amplify mock function should use the runtime described in the function's cloudformation template. Or perhaps use the 'default' version of NodeJS, perhaps with a warning that the local node may be different than the one the Lambda will run in the cloud.

Reproduction steps

  1. Make a lambda that prints the version of node it's using
  2. amplify mock function
  3. Behold! An old mysterious node is found and used.

GraphQL schema(s)

No response

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

@josefaidt on Discord

It appears the CLI is likely using the Node 14 runtime shipped with the packaged CLI rather than the available Node binary on the system

(Looks like amplify mock is missing from the amplify commands drop down.)

Thanks!

josefaidt commented 2 years ago

Hey @dmost714 :wave: thanks for taking the time to raise this! I've gone ahead and marked this as a feature request to improve the function mock capability to use the runtime version specified in the function's CloudFormation template, and have also added a docs label to update our docs to reflect this current limitation 🙂

parvusville commented 1 year ago

Also facing this issue, and it does make development workflow way more complicated than it has to be. Support for using system node version would be crucial, especially considering that Node 14 is also about to reach EOL.

Makes me wonder, doesn't other people use local Mocking, or how this issue hasn't gotten more traction? What sort of development workflows do people use with Node lambdas?

parvusville commented 1 year ago

Hey, apparently mocking now always uses Node 18? @josefaidt

dmost714 commented 1 year ago

Hey, apparently mocking now always uses Node 18? @josefaidt

Confirmed. Ran a mock. It was the old node. Upgraded to Amplify cli v12.0.3, ran mock, and it's using v18.15.0. My local node is 18.12.1.

I edited the lambda's cloudformation-template.json file to downgrade the lambda to v16 and ran mock. Mock used v18 anyway. I suppose people on an old node can/should upgrade. Perhaps print a warning when versions mismatch. People will use APIs from and test against v18, then deploy/run v16. Nothing fun comes from that.

Thrilled I can mock Lambdas with Amplify environment context again!

AleksandarGT commented 1 year ago

Hey, apparently mocking now always uses Node 18? @josefaidt

Confirmed. Ran a mock. It was the old node. Upgraded to Amplify cli v12.0.3, ran mock, and it's using v18.15.0. My local node is 18.12.1.

I edited the lambda's cloudformation-template.json file to downgrade the lambda to v16 and ran mock. Mock used v18 anyway. I suppose people on an old node can/should upgrade. Perhaps print a warning when versions mismatch. People will use APIs from and test against v18, then deploy/run v16. Nothing fun comes from that.

Thrilled I can mock Lambdas with Amplify environment context again!

I am using amplify cli v12.1.1 and when I mock a function it uses node 14. I am using node canvas which has binaries built specifically for the given node version, so this unexpected node version is making mocking useless in my use case.