aws-amplify / amplify-cli

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

Failed to pull the backend CLI 12.12.0 #13771

Open bergmorten opened 1 month ago

bergmorten commented 1 month ago

How did you install the Amplify CLI?

amplify build console

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

No response

Amplify CLI Version

12.12.0

What operating system are you using?

als2023 (amplify build console)

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

Nope

Describe the bug

I tried to deploy a new app with the new amplify console, and ran into multiple errors.

  1. Setting node version to 20 was ignored, and first build failed because of node 14 did not meet requirements
  2. Edit then build setting again to set version 20, still ignored
  3. Edit build environment, which suddenly had a _LIVE_UPDATES variable for my branch with node 14, modified this to version 20
  4. Prephase build did now succeed :-), but backend build phase is failing (see log below).
  5. Since amplify-cli 12.12.0 was released today, I then try tied lock it to my last known working version 12.11.1, but build setting and _LIVE_UPDATES with this entry is ignored and 12.12.0 is used.

The error message is that it Failed to pull the backend, and There was an error initializing your environment. Is this because my first build failed?

2024-05-08T15:26:29.577Z [INFO]: # Completed phase: preBuild
# Starting phase: build
2024-05-08T15:26:33.297Z [INFO]: Amplify AppID found: d280i329tozog7. Amplify App name is: wcs
2024-05-08T15:26:33.344Z [INFO]: Backend environment wcs found in Amplify Console app: wcs
2024-05-08T15:26:35.233Z [WARNING]: - Fetching updates to backend environment: wcs from the cloud.
2024-05-08T15:26:35.544Z [WARNING]: - Building resource api/bathymetry
2024-05-08T15:26:35.582Z [WARNING]: - Building resource api/costExplorer
2024-05-08T15:26:35.601Z [WARNING]: - Building resource api/customerAPI
2024-05-08T15:26:52.800Z [INFO]: ✅ GraphQL schema compiled successfully.
Edit your schema at /codebuild/output/src144640090/src/aws-clients/amplify/backend/api/customerAPI/schema.graphql or place .graphql files in a directory at /codebuild/output/src144640090/src/aws-clients/amplify/backend/api/customerAPI/schema
2024-05-08T15:26:52.805Z [WARNING]: - Building resource api/support
2024-05-08T15:26:52.818Z [WARNING]: - Building resource api/vehicleCertificates
2024-05-08T15:26:52.833Z [WARNING]: - Building resource auth/clientwebe913f698
2024-05-08T15:26:52.875Z [WARNING]: - Building resource auth/userPoolGroups
2024-05-08T15:26:52.901Z [WARNING]: - Building resource custom/SocketServerInterface
2024-05-08T15:26:52.901Z [WARNING]: - Building custom resources
2024-05-08T15:27:05.456Z [WARNING]: - Building resource storage/customerData
2024-05-08T15:27:05.577Z [WARNING]: ✔ Successfully pulled backend environment wcs from the cloud.
2024-05-08T15:27:05.920Z [WARNING]: ✖ There was an error initializing your environment.
2024-05-08T15:27:09.183Z [INFO]: 🛑 Failed to pull the backend.
2024-05-08T15:27:09.190Z [INFO]: Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
2024-05-08T15:27:09.198Z [INFO]:
2024-05-08T15:27:09.198Z [INFO]: Session Identifier: 6119fbfb-77de-45c6-ae3a-4853fae72c93
2024-05-08T15:27:09.244Z [ERROR]: !!! Build failed2024-05-08T15:27:09.244Z [ERROR]: !!! Error: Command failed with exit code 1
2024-05-08T15:27:09.244Z [INFO]: # Starting environment caching...
2024-05-08T15:27:09.244Z [INFO]: # Environment caching completed
2024-05-08T15:27:09.244Z [ERROR]: !!! Error: Command failed with exit code 1
2024-05-08T15:27:09.244Z [INFO]: # Starting environment caching...
2024-05-08T15:27:09.244Z [INFO]: # Environment caching completed

image

image

image

Expected behavior

  1. Allow to set node version when creating a app through console
  2. Allow to set amplify-cli version through build-setting
  3. Build should not fail

Reproduction steps

Try create new app via amplify console, which has a package.json with node requirement of node v20.

Project Identifier

No response

Log output

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

Additional information

No response

Before submitting, please confirm:

bergmorten commented 1 month ago

Update. I manage to set cli version to 12.11.1 (there was still a _LIVE_UPDATES entry for my branch which overwrite the global build setting). I think it is very odd that the console creates environments which duplicates the global variables.

Still the same error with 12.11.1 so 12.12.0 is not the culprit.

bergmorten commented 1 month ago

Another update.

I then deleted the created backend environment and did a redeploy with amplify cli 12.11.0 and it worked :-)

I do not know if the issue was with 12.12.0 or that the first build failed with incorrect node version....

ykethan commented 1 month ago

Hey @bergmorten, thank you for reaching out. Glad to hear you were able to mitigate the issue, if the issue reoccurs could you try adding --debug to the command which should provide some verbose logging. But the change in the node version may be the reason for the failed build, but do let us know if the issue reoccurs.

bergmorten commented 1 month ago

What I think happen was that even when preBuild phase was failing the amplify-cli created an empty backend environment. So when preBuild phase was fixed and it did checkout an empty invalid environment.

It should not have created an empty / invalid environment?

The attempts which failed contained these lines:

2024-05-08T15:06:25.556Z [WARNING]: ✔ Successfully pulled backend environment wcs from the cloud.
2024-05-08T15:06:25.841Z [WARNING]: ✖ There was an error initializing your environment.
2024-05-08T15:06:29.195Z [INFO]: 🛑 Failed to pull the backend.

When I deleted the backend environment it did create a new environment.

2024-05-08T16:15:40.672Z [INFO]: Adding backend environment wcs to AWS Amplify app: XXXXXXXXX

ykethan commented 1 month ago

@bergmorten the branch should pull the backend that the app was connected to. If the backend does not exist it tries to create one for you.