amplify-cli
amplify-cli copied to clipboard
Issue with amplify push after adding function
How did you install the Amplify CLI?
npm install -g @aws-amplify/cli
If applicable, what version of Node.js are you using?
v20.11.1
Amplify CLI Version
12.10.1
What operating system are you using?
Ubuntu 22.04
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes.
Describe the bug
I added a function using amplify add function. Now whenever I try to run amplify push, it was throwing error related to yarn.
Initially I was getting error
🛑 Packaging lambda function failed with the error
Command failed with exit code 1: yarn --no-bin-links --production
I tried all the possible solution but nothing worked. After that I updated yarn to version "4.1.0", Now I am getting
🛑 Received error [Error: Command failed with exit code 1: yarn --version] running command [yarn --version]
In function source "npm i" is working, which switch the use of yarn to npm but then I get
🛑 Packaging lambda function failed with the error
Command failed with exit code 243: npm install --no-bin-links --production
Expected behavior
It should allow me to push successfully
Reproduction steps
- amplify add function
- amplify push
- Initially by default it uses yarn
- Go to function and run "npm i"
- It switches to npm. [npm is not installed using sudo]
- Both npm/yarn throwing error
Project Identifier
1a1531b527bd8301a262c456a8ba59a0
Log output
Yarn Error
2024-02-15T08:01:24.026Z|info : amplify push core {"debug":true,"yes":false}
2024-02-15T08:01:24.065Z|info : @aws-amplify/amplify-cli-core.banner-message/index.ts.fetch banner messages from https://aws-amplify.github.io/amplify-cli/banner-message.json({}
2024-02-15T08:01:25.689Z|info : amplify-provider-awscloudformation.zip-util.downloadZip.s3.getFile([{"Key":"[***]rent-[***]ud-[***]d.zip"},null])
2024-02-15T08:01:25.691Z|info : amplify-provider-awscloudformation.aws-s3.s3.getFile([{"Key":"[***]rent-[***]ud-[***]d.zip","Bucket":"[***]ify-[***]ernext-[***]ev-[***]56-[***]ment"}])
2024-02-15T08:01:26.112Z|info : amplify-provider-awscloudformation.initialize-env.run.cfn.updateamplifyMetaFileWithStackOutputs([{"StackName":"[***]ify-[***]ernext-[***]ev-[***]56"}])
2024-02-15T08:01:26.118Z|info : amplify-provider-awscloudformation.aws-cfn.updateamplifyMetaFileWithStackOutputs.cfn.listStackResources([{"StackName":"[***]ify-[***]ernext-[***]ev-[***]56"}])
2024-02-15T08:01:26.370Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]ify-[***]ernext-[***]ev-[***]56"}])
2024-02-15T08:01:26.557Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]rmation:ap-[***]th-[***]30:stack/[***]ify-[***]ernext-[***]ev-[***]56-[***]ternext-[***]IYERY8/[***]4040-[***]21-[***]ee-[***]53-[***]eabd8"}])
2024-02-15T08:01:26.559Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]rmation:ap-[***]th-[***]30:stack/[***]ify-[***]ernext-[***]ev-[***]56-[***]extacc08a84-[***]FJYFP/[***]a040-[***]a5-[***]ed-[***]a1-[***]30c0e"}])
2024-02-15T08:01:26.561Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]rmation:ap-[***]th-[***]30:stack/[***]ify-[***]ernext-[***]ev-[***]56-[***]eronext-[***]DHKRHS/[***]d5c0-[***]4a-[***]ed-[***]6b-[***]63924"}])
2024-02-15T08:01:26.740Z|info : amplify-provider-awscloudformation.aws-s3.s3.getFile([{"Key":"[***]ify-[***]json","Bucket":"[***]ify-[***]ernext-[***]ev-[***]56-[***]ment"}])
2024-02-15T08:01:31.192Z|error : Received error [Error: Command failed with exit code 1: yarn --version] running command [yarn --version]
ShellCommandExecutionError: Received error [Error: Command failed with exit code 1: yarn --version] running command [yarn --version]
NPM error
2024-02-15T07:57:30.438Z|info : amplify push core {"debug":true,"yes":false}
2024-02-15T07:57:30.480Z|info : @aws-amplify/amplify-cli-core.banner-message/index.ts.fetch banner messages from https://aws-amplify.github.io/amplify-cli/banner-message.json({}
2024-02-15T07:57:32.589Z|info : amplify-provider-awscloudformation.zip-util.downloadZip.s3.getFile([{"Key":"[***]rent-[***]ud-[***]d.zip"},null])
2024-02-15T07:57:32.592Z|info : amplify-provider-awscloudformation.aws-s3.s3.getFile([{"Key":"[***]rent-[***]ud-[***]d.zip","Bucket":"[***]ify-[***]ernext-[***]ev-[***]56-[***]ment"}])
2024-02-15T07:57:33.098Z|info : amplify-provider-awscloudformation.initialize-env.run.cfn.updateamplifyMetaFileWithStackOutputs([{"StackName":"[***]ify-[***]ernext-[***]ev-[***]56"}])
2024-02-15T07:57:33.104Z|info : amplify-provider-awscloudformation.aws-cfn.updateamplifyMetaFileWithStackOutputs.cfn.listStackResources([{"StackName":"[***]ify-[***]ernext-[***]ev-[***]56"}])
2024-02-15T07:57:33.337Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]ify-[***]ernext-[***]ev-[***]56"}])
2024-02-15T07:57:33.503Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]rmation:ap-[***]th-[***]30:stack/[***]ify-[***]ernext-[***]ev-[***]56-[***]ternext-[***]IYERY8/[***]4040-[***]21-[***]ee-[***]53-[***]eabd8"}])
2024-02-15T07:57:33.504Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]rmation:ap-[***]th-[***]30:stack/[***]ify-[***]ernext-[***]ev-[***]56-[***]extacc08a84-[***]FJYFP/[***]a040-[***]a5-[***]ed-[***]a1-[***]30c0e"}])
2024-02-15T07:57:33.506Z|info : amplify-provider-awscloudformation.aws-cfn.describeStack.cfn.describeStacks([{"StackName":"[***]rmation:ap-[***]th-[***]30:stack/[***]ify-[***]ernext-[***]ev-[***]56-[***]eronext-[***]DHKRHS/[***]d5c0-[***]4a-[***]ed-[***]6b-[***]63924"}])
2024-02-15T07:57:33.688Z|info : amplify-provider-awscloudformation.aws-s3.s3.getFile([{"Key":"[***]ify-[***]json","Bucket":"[***]ify-[***]ernext-[***]ev-[***]56-[***]ment"}])
2024-02-15T07:57:39.726Z|error : Packaging lambda function failed with the error
Command failed with exit code 243: npm install --no-bin-links --production
PackagingLambdaFunctionError: Packaging lambda function failed with the error
Command failed with exit code 243: npm install --no-bin-links --production
Additional information
No response
Before submitting, please confirm:
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
Hey @sidshrivastav, thank you for reaching. The issue is currently being tracked on https://github.com/aws-amplify/amplify-cli/issues/13001 and https://github.com/aws-amplify/amplify-cli/issues/13377. Refer to the workarounds posted here: https://github.com/aws-amplify/amplify-cli/issues/13001#issuecomment-1906930211 and https://github.com/aws-amplify/amplify-cli/issues/13377#issuecomment-1901602090
After switching to npm, was the amplify.state
modified? could you provide us a snippet of the file.
After switching to npm, was the amplify.state modified? could you provide us a snippet of the file.
hey @ykethan, sorry I am not sure how to check amplify state, can you help me with that?
Also with yarn 3, 4 I am getting,
🛑 Received error [Error: Command failed with exit code 1: yarn --version] running command [yarn --version]
and with classic verison:
🛑 Packaging lambda function failed with the error Command failed with exit code 1: yarn --no-bin-links --production
Workaround you shared, I don't think is related to that.
Hey @sidshrivastav, the amplify.state
may be hidden on Vscode. Could you open the .vscode/setting.json
and set the "amplify/**/amplify.state"
as false
.
Additionally, refer to comment https://github.com/aws-amplify/amplify-cli/issues/13377#issuecomment-1948367193 providing information on using yarn 4 with function by modifying the amplify.state
.
Additionally, curious on the error message Command failed with exit code 243: npm install --no-bin-links --production
. Could you provide us the npm version currently installed.
Additionally, curious on the error message Command failed with exit code 243: npm install --no-bin-links --production. Could you provide us the npm version currently installed.
npm version is 10.2.4
Initially when "amplify push" ran with yarn by default
Error:
Received error [Error: Command failed with exit code 1: yarn --version] running command [yarn --version]
cd to function src, and ran npm i
Error
Packaging lambda function failed with the error Command failed with exit code 243: npm install --no-bin-links --production
Amplify state remains same. amplify.state
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js"
}
@ykethan Additionally I ran it on docker container just to test on latest nodejs image, "amplify push" didn't push due to permission but i didn't got these issues.
@sidshrivastav thank you for the information. We can add/modify the scripts in the state to modify the build command.
For example default lambda function:
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js",
"scripts": {
"build": "npm install --no-bin-links --production"
}
}
or
{
"pluginId": "amplify-nodejs-function-runtime-provider",
"functionRuntime": "nodejs",
"useLegacyBuild": true,
"defaultEditorFile": "src/index.js",
"scripts": {
"build": "yarn"
}
}
Hey, I started using nix environment where amplify is working. I test this modification on scripts and let you know
Closing the issue due to inactivity. Do reach out to us if you require any assistance.
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.