amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

`amplify init` fails when executed inside an existing amplify project

Open pavellazar opened this issue 4 years ago • 7 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [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.

How did you install the Amplify CLI?

npm

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

14

Amplify CLI Version

9.1.0

What operating system are you using?

macOS/Windows

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

no

Amplify Categories

Not applicable

Amplify Commands

init

Describe the bug

Executing amplify init in a nested directory of a amplify project fails with `.../amplify/cli.json' does not exist

Expected behavior

Nested projects are not supported and the execution should fail fast

Reproduction steps

Test 1

  1. mkdir nested-app
  2. cd nested-app
  3. amplify init
  4. mkdir nested-app-2
  5. cd nested-app-2
  6. amplify init -> macOS / win : ERROR

Test 2

  1. mkdir nested-app
  2. cd nested-app
  3. amplify init
  4. cd amplify
  5. mkdir nested-app
  6. cd nested-app pwd -> ~/nested-app/amplify/nested-app
  7. amplify init -> macOS / win : ERROR

GraphQL schema(s)

# Put schemas below this line


Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

pavellazar avatar Jul 12 '22 15:07 pavellazar

This bug also causes you to not be able to delete apps from the Amplify console either, so you have loaded infrastructure you can't get rid of.

billygerhard avatar Jul 14 '22 13:07 billygerhard

Hi @billygerhard, can you try using the AWS CLI to delete the apps: aws amplify delete-app --app-id <app-di> --region <app-region>

pavellazar avatar Jul 14 '22 15:07 pavellazar

@lazpavel my issue is very strange here. I work at an organisation named Amplify (you can see my github organisation). I am using my organisation laptop where the default user is Amplify path /Users/Amplify.

i am using aws amplify cli version 9.1.0. I am seeing the following error when i have done amplify init in my flutter project path /Users/Amplify/Varun/workspace/amplify_fb_auth .

Initializing project in the cloud...

CREATE_IN_PROGRESS AuthRole AWS::IAM::Role Thu Jul 14 2022 23:55:21 GMT+0530 (India Standard Time) Resource creation Initiated
⠇ Initializing project in the cloud...

CREATE_COMPLETE UnauthRole AWS::IAM::Role Thu Jul 14 2022 23:55:38 GMT+0530 (India Standard Time) 
CREATE_COMPLETE AuthRole   AWS::IAM::Role Thu Jul 14 2022 23:55:39 GMT+0530 (India Standard Time) 
⠴ Initializing project in the cloud...

CREATE_COMPLETE DeploymentBucket AWS::S3::Bucket Thu Jul 14 2022 23:55:42 GMT+0530 (India Standard Time) 
⠧ Initializing project in the cloud...

CREATE_COMPLETE amplify-amplifyfbauth-dev-XXXXXX AWS::CloudFormation::Stack Thu Jul 14 2022 23:55:44 GMT+0530 (India Standard Time) 
✔ Successfully created initial AWS cloud resources for deployments.
✔ Help improve Amplify CLI by sharing non sensitive configurations on failures (y/N) · yes
Error: File at path: '/Users/Amplify/Varun/workspace/amplify_fb_auth/amplify/cli.json' does not exist
   at Function.readJson (/snapshot/repo/build/node_modules/amplify-cli-core/lib/jsonUtilities.js:40:19)
   at StateManager.getData (/snapshot/repo/build/node_modules/amplify-cli-core/lib/state-manager/stateManager.js:309:56)
   at StateManager.getCLIJSON (/snapshot/repo/build/node_modules/amplify-cli-core/lib/state-manager/stateManager.js:254:25)
   at DebugConfig.getCLIJson (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/app-config/debug-config.js:31:48)
   at DebugConfig.writeShareProjectConfig (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/app-config/debug-config.js:44:30)
   at DebugConfig.setAndWriteShareProject (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/app-config/debug-config.js:66:14)
   at onSuccess (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/init-steps/s9-onSuccess.js:77:45)
   at processTicksAndRejections (internal/process/task_queues.js:95:5)
   at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/commands/init.js:30:13)
   at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:292:9)
   at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
   at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
   at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:165:13)

But when i see the cli.json file is getting created at /Users/Amplify/cli.json .

Solution: What i have done is i have placed the file in required position (/Users/Amplify/Varun/workspace/amplify_fb_auth/amplify/cli.json) and made amplify init with different environment name (ex: learn) which different from the first amplify init (eg: dev)

I request you to revisit your folder and file creation procedure so that we do not have such issue.

Cheers!!!

vmadupu9 avatar Jul 14 '22 18:07 vmadupu9

Hi @vmadupu9, thank you for reporting this, I was able to reproduce the issue

pavellazar avatar Jul 14 '22 19:07 pavellazar

@lazpavel I did try that when it first happened, and it would not delete.

billygerhard avatar Jul 19 '22 20:07 billygerhard

@billygerhard can you paste the output of this command? aws amplify delete-app --app-id <app-di> --region <app-region>

pavellazar avatar Jul 20 '22 16:07 pavellazar

I'm solved it.

When i install the @aws-amplify/cli, my node version was 9.x.

To solve, I run nvm use 16, and reinstall @aws-amplify/cli@latest.

pkhadson avatar Nov 09 '22 15:11 pkhadson