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

Amplify project fails for all deployments with different environments #13572

Closed
2 tasks done
jmendozaTerrenta opened this issue Feb 2, 2024 · 5 comments
Closed
2 tasks done
Labels
hosting Issues tied to hosting category pending-triage Issue is pending triage

Comments

@jmendozaTerrenta
Copy link

jmendozaTerrenta commented Feb 2, 2024

How did you install the Amplify CLI?

npm install -g @aws-amplify/cli

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

16.18.1

Amplify CLI Version

12.10.1

What operating system are you using?

Windows 11

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

Deleted DynamoDB table. The DynamoDB table was automatically generated from Schema.graphql

Describe the bug

Environments can be pushed correctly from the amplify cli locally, however, every deployment (event the ones not being updated a while a go) fail with the following exit code:

# Starting phase: build
                                 # Executing command: amplify push --simple
2024-02-02T20:41:38.636Z [INFO]: :advertencia: Could not resolve either appId, environment name or both. Skipping environment check for function secrets and environment variables
2024-02-02T20:41:39.692Z [INFO]: :señal_octogonal: Current environment cannot be determined.
2024-02-02T20:41:39.693Z [INFO]: Resolution: Use 'amplify init' in the root of your app directory to create a new environment.
                                 Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
2024-02-02T20:41:39.735Z [INFO]:
2024-02-02T20:41:39.736Z [INFO]: Session Identifier: 979bef86-1148-4bf5-a8fa-2a3e39557a40
2024-02-02T20:41:39.757Z [ERROR]: !!! Build failed
2024-02-02T20:41:39.757Z [ERROR]: !!! Error: Command failed with exit code 1
2024-02-02T20:41:39.757Z [INFO]: # Starting environment caching...
2024-02-02T20:41:39.757Z [INFO]: # Environment caching completed
Terminating logging...

This does not happen when trying amplify push locally.

Expected behavior

The automatic CI/CD deployments should either recognize the correct environment they are associated with and deploy, or show an error as to why the environment can't be recognized and let me fix it manually from the CLI or the AWS console.

Reproduction steps

Unable to reproduce in an empty project

Project Identifier

Project Identifier: aed6dee85659e018bbac86d0244fd500

Log output

# Put your logs below this line
# Starting phase: build
                                 # Executing command: amplify push --simple
2024-02-02T20:41:38.636Z [INFO]: :advertencia: Could not resolve either appId, environment name or both. Skipping environment check for function secrets and environment variables
2024-02-02T20:41:39.692Z [INFO]: :señal_octogonal: Current environment cannot be determined.
2024-02-02T20:41:39.693Z [INFO]: Resolution: Use 'amplify init' in the root of your app directory to create a new environment.
                                 Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
2024-02-02T20:41:39.735Z [INFO]:
2024-02-02T20:41:39.736Z [INFO]: Session Identifier: 979bef86-1148-4bf5-a8fa-2a3e39557a40
2024-02-02T20:41:39.757Z [ERROR]: !!! Build failed
2024-02-02T20:41:39.757Z [ERROR]: !!! Error: Command failed with exit code 1
2024-02-02T20:41:39.757Z [INFO]: # Starting environment caching...
2024-02-02T20:41:39.757Z [INFO]: # Environment caching completed
Terminating logging...

Additional information

Multiple deployments have failed after deleting a DynamoDB table.
Also when trying to pull the affected environment locally, the following errors prompt

Failed to resolve AppId. Skipping parameter download.
? Select the authentication method you want to use: AWS profile
× Initializing your environment: terrprod
× There was an error initializing your environment.
:señal_octogonal: Could not initialize platform for 'terrprod': Missing required key 'Bucket' in params 

and

amplify pull --appId d172eiraov05tj --envName terrprod
:señal_octogonal: Environment name is invalid.
Resolution: Run amplify env list to get a list of valid environments.
Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/
Session Identifier: 022d85a2-cdc7-474f-bf36-5f17c6724047

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@jmendozaTerrenta jmendozaTerrenta added the pending-triage Issue is pending triage label Feb 2, 2024
@jmendozaTerrenta
Copy link
Author

jmendozaTerrenta commented Feb 5, 2024

Additional info:

During the "Cloning repository" phase I always get the following error:

2024-02-05T15:45:09.487Z [INFO]: # Retrieving environment cache...
2024-02-05T15:45:09.534Z [WARNING]: ! Unable to write cache: {"code":"ERR_BAD_REQUEST","message":"Request failed with status code 404"})}
2024-02-05T15:45:09.639Z [INFO]: ---- Setting Up SSM Secrets ----
2024-02-05T15:45:09.639Z [INFO]: SSM params {"Path":"/amplify/d172eiraov05tj/terrdev/","WithDecryption":true}

These seems to be related but since the cloning phase didn't raise an error I thought it might not matter.

@ykethan
Copy link
Member

ykethan commented Feb 5, 2024

Hey @jmendozaTerrenta, thank you for reaching out. On the Amplify console, were there any changes to the backend connected to hosting/git branch?

@ykethan ykethan added hosting Issues tied to hosting category pending-response Issue is pending response from the issue author labels Feb 5, 2024
@jmendozaTerrenta
Copy link
Author

We did multiple push commands to try and resync the bad environment, however, during the process we deleted manually a DynamoDB table that was being used.

After the push in which the first issue was raised and the one in which a table was deleted it seems the Amplify environment variables were corrupted

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Feb 5, 2024
@jmendozaTerrenta
Copy link
Author

jmendozaTerrenta commented Feb 5, 2024

The issue has been fixed. After trying to fix the environments that were corrupted we concentrated on the error raised during the "Cloning repository" phase. Turns out that resetting the environment cache did the trick and after that, it was just an issue of fixing the underlying error for environments affected.

For future reference, the error message ! Unable to write cache: {"code":"ERR_BAD_REQUEST","message":"Request failed with status code 404"})} should stop the "Cloning repository" phase and show as a fix suggestion resetting the environment cache. We were pretty confused as to why this phase seemed to be finished successfully but the Backend phase didn't, when the error was a result of an unhandled error during the "Cloning repository" phase.

The fix was adding - envCache --set stackInfo "" to the amplify.yml file in the Build settings before the push command, running a build and then fixing the true underlying issue.

amplify.yml:

version: 1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - envCache --set stackInfo ""
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - npm ci 
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: dist/Terrenta
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Reference to the issue (from amplify-hosting repository) that helped me:
How to reset amplify build - envCache

Copy link

github-actions bot commented Feb 5, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

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.
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
hosting Issues tied to hosting category pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

2 participants