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

amplify pull: No Amplify backend project files detected within this folder.

Open gxxcastillo opened this issue 3 years ago • 10 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?

16.17.1

Amplify CLI Version

10.5.1

What operating system are you using?

Mac

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

No

Amplify Categories

api

Amplify Commands

pull

Describe the bug

Following the instructions from https://docs.amplify.aws/cli/project/monorepo/ I did a amplify pull from my web client folder and I was able to successfully pull my backend project. Note, I answered "no" when asked "Do you plan on modifying this backend?".

The next time I ran amplify pull, however, it failed with: "No Amplify backend project files detected within this folder."

Expected behavior

To not get an error when I run amplify pull a second time

Reproduction steps

Follow the steps from this post: https://docs.amplify.aws/cli/project/monorepo/#step-3b-integrate-backend-with-angular-app

GraphQL schema(s)

type Todo @model {
  id: ID!
  stage: StageOptions
  name: String!
  description: String
}

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

I noticed a related bugfix (#11415) by @edwardfoyle. It does seem that version 10.5.1 should have that fix.

gxxcastillo avatar Dec 06 '22 21:12 gxxcastillo

Ultimately, I'm trying to set up hosting such that multiple clients will be able to use the amplify backend that I've created (I posted in Discord about it here)

So, piggy backing on this issue: How would I go about setting up hosting for my web application? I've tried multiple ways using different combinations of amplify pull and amplify init and amplify add hosting but have been coming up across this error:

✖ There was an error initializing your environment.
🛑 File at path: '.../amplify/backend/backend-config.json' does not exist

gxxcastillo avatar Dec 06 '22 22:12 gxxcastillo

Hey @gxxcastillo :wave: thanks for raising this! Although this is noted as an issue in the thread of a few others, I will keep this open and mark as a bug to track separately.

  • https://github.com/aws-amplify/amplify-cli/issues/11066
  • https://github.com/aws-amplify/amplify-cli/issues/11487
  • https://github.com/aws-amplify/amplify-cli/issues/11372

So, piggy backing on this issue: How would I go about setting up hosting for my web application?

Unfortunately when you select "No" to "do you plan on modifying this backend" you will be unable to add additional resource categories such as Hosting. While the CLI works to improve this functionality, you can create a separate Amplify project in the Amplify Hosting console and point your frontend to the existing project's backend image

josefaidt avatar Dec 07 '22 00:12 josefaidt

Hi @josefaidt , thanks again for the help. I've done as you've instructed, however, it does not seem to generate the aws-exports file. I saw this documentation about unchecking the "enable ful-stack continuous deployments" but it does not seem to work in that the build is not able to find the aws-exports file (I'm assuming it got generated but not sure how to verify). Where does the aws-exports file get generated to?

I've also tried doing amplifyPush --simple from within my amplify folder which I saw mentioned in some other places but that ended up causing a push (which fails) which is not what I want.

gxxcastillo avatar Dec 22 '22 01:12 gxxcastillo

Some more digging around and I found reference to using amplify env checkout {stage}

However, when I do that I get this error:

🛑 Current environment cannot be determined.
Resolution: Use 'amplify init' in the root of your app directory to create a new environment.

gxxcastillo avatar Dec 22 '22 02:12 gxxcastillo

Hey @gxxcastillo :wave: the aws-exports.js file will be created in the location specified as the "SourceDir" which can be found in amplify/.config/project-config.json or by running amplify configure project

josefaidt avatar Dec 22 '22 20:12 josefaidt

Thanks @josefaidt. Does this mean I could remove the commands from the build script that attempt to generate the aws-exports file? I just tried doing this but now my build breaks saying it could not find the aws-exports file. The file is found when I run the build locally and only breaks when I try to deploy.

gxxcastillo avatar Dec 22 '22 23:12 gxxcastillo

Hey @gxxcastillo I believe you will still want the amplifyPush --simple step in your backend build's step:

version: 1
backend:
  phases:
    preBuild:
      commands:
        - amplifyPush --simple
frontend:
# ...

or you can use the AMPLIFY_SKIP_BACKEND_BUILD environment variable in Amplify Hosting to skip the build, which should run amplify pull behind the scenes and generate this file https://docs.aws.amazon.com/amplify/latest/userguide/environment-variables.html#amplify-console-environment-variables

josefaidt avatar Dec 23 '22 00:12 josefaidt

Thanks @josefaidt, are you saying that if I use AMPLIFY_SKIP_BACKEND_BUILD , then I don't need to add a command to the build steps to generate the aws-exports file - it will generate it automatically?

gxxcastillo avatar Dec 23 '22 00:12 gxxcastillo

Ok, after many hours of help from the AWS support team over the course of multiple days, I was able to solve this as follows:

  • I undid the suggestion from here, leaving the "CI/CD" checkbox unchecked and the environment unselected (unfortunately, there were enough twists and turns in this setup to where I forgot exactkly why this didn't work - it have been something to do with where it placed the aws-exports file)

  • I manually created a "BACKEND_APP_ID" and "USER_BRANCH" environment variable and then reference them in the call to amplify pull

  • since I'm in a monorepo, I cd into the specific amplify backend folder and run amplify pull from there

version: 1
applications:
  - frontend:
      phases:
        build:
          commands:
            - yarn install
            - cd apps/my-amplify-backend
            - amplify pull --appId $BACKEND_APP_ID --envName $USER_BRANCH -y
  • Additionally, I have the following environment configs configured:
AMPLIFY_DIFF_DEPLOY = false
_LIVE_UPDATES = [{"name":"Amplify CLI","pkg":"@aws-amplify/cli","type":"npm","version":"latest"}]
AMPLIFY_BACKEND_PULL_ONLY = true

gxxcastillo avatar Jan 09 '23 18:01 gxxcastillo

The error appears because there are two files missing from amplify/backend folder: backend-config.json and amplify-meta.json . At least that was my case.

Mikimann avatar Dec 13 '23 16:12 Mikimann