Amplify-cli: Does `amplify push` run `npm install` or anything similar for lambdas before push?

Created on 5 Jun 2020  路  8Comments  路  Source: aws-amplify/amplify-cli

Which Category is your question related to?
functions

Amplify CLI Version
4.21.0

What AWS Services are you utilizing?
Lambda

Provide additional details e.g. code snippets

If we update package.json in lambda code but not run 'npm install' manually, and then do amplify push, the lambdas in the backend are not updated with the specific packages we want in package.json. We have to do npm install to update package-lock.json locally first before doing amplify push.

Is this expected behaviour? It's very annoying to run 'npm install' on multiple lambdas before doing amplify push...

bug functions pending-release

All 8 comments

I see that I can use https://docs.amplify.aws/cli/function/build-options to do this.

Am I able to target lambdas via wildcard (e.g. amplify:*)? Or target all lambdas, or must I put a script line for each lambda?

Looking at https://github.com/aws-amplify/amplify-cli/blob/7b1f0f2c7bb67a9d154e8462643fb0fe35e88399/packages/amplify-nodejs-function-runtime-provider/src/utils/legacyBuild.ts#L32 in more detail...

It looks like you run 'npm install' on if the build is state, by looking at timestamps of the node modules.

But it doesn't seem that you look at timestamp of package.json.

I suggest you also look at the timestamp of package.json, and if it has changed, run npm install.

Yes I just did a test, in my package.json I changed the version of one of the packages to a major version that does not exist. I then ran amplify push. Amplify correctly said the lambda was due for an update. The amplify push then succeeded. It should not have however because npm install would have failed. Therfore amplify did not run npm install when I changed package.json.

So I think this is a bug - amplify said my lambda was due for an update (because package.json was touched) but did not really update the lambda properly.

Even buildhook workaround wouldn't work since the build hook only runs if amplify determine the build is stale...so I"m stuck with running npm install manually.

Hello @hisham
We are looking at adding custom scripts and variables as an enhancement. As for the changes in package.json this is something we can review with the team.

@hisham The fix for this is available in the latest release of the CLI (4.22.0)

I was able to resolve this by updating amplify.yml to build lambda layer before calling amplifyPush
Example of build script.

build:
commands:
- '# Execute module build for lambda layers'
- cd ./amplify/backend/function/viewerlayer/lib/nodejs
- yarn install
- echo "# Back to root folder"
- cd ../../../../../..
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicksmithr picture nicksmithr  路  3Comments

MageMasher picture MageMasher  路  3Comments

jexh picture jexh  路  3Comments

adriatikgashi picture adriatikgashi  路  3Comments

davo301 picture davo301  路  3Comments