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

Hosting with imported Cognito Auth fails to build the backend #2269

Closed
4 tasks done
tomasff opened this issue Sep 15, 2021 · 10 comments
Closed
4 tasks done

Hosting with imported Cognito Auth fails to build the backend #2269

tomasff opened this issue Sep 15, 2021 · 10 comments
Labels
archived This issue has been locked. backend-builds bug Something isn't working documentation transferred This issue was transferred from another Amplify project

Comments

@tomasff
Copy link

tomasff commented Sep 15, 2021

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

No response

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

No response

Amplify CLI Version

latest

What operating system are you using?

WSL Ubuntu

Amplify Categories

auth, hosting

Amplify Commands

Not applicable

Describe the bug

Upon trying to deploy this application which uses imported auth with Cognito, the build fails mentioning that the input parameters userPoolId, webClientId, nativeClientId are missing. I have checked the Amplify Environment variables docs but didn't find environment variables specified to set these input parameters.

Expected behavior

Environment variables should be available to set these parameters.

Reproduction steps

  1. Create a React application in the Amplify Console.
  2. Enable auth with a Cognito pool
  3. Attempt to build the application with the following build settings using Amplify Hosting
version: 1
backend:
  phases:
    build:
      commands:
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
      commands:
        - yarn run build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

The application I'm trying to deploy is available here.

GraphQL schema(s)

No response

Log output

# Put your logs below this line

2021-09-15T20:39:59.368Z [INFO]: Git SSH Key acquired
2021-09-15T20:39:59.437Z [INFO]: # Cloning repository: [email protected]:WarwickAI/wai-platform.git
2021-09-15T20:39:59.477Z [INFO]: Agent pid 137
2021-09-15T20:39:59.481Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
2021-09-15T20:39:59.772Z [INFO]: Cloning into 'wai-platform'...
2021-09-15T20:40:00.370Z [INFO]: Warning: Permanently added the RSA host key for IP address '140.82.121.3' to the list of known hosts.
2021-09-15T20:40:06.830Z [INFO]: # Switching to commit: aa2d8914354da2216e44a15ab5df1bbfabb30109
2021-09-15T20:40:06.934Z [INFO]: Agent pid 150
2021-09-15T20:40:06.935Z [INFO]: Identity added: /root/.ssh/git_rsa (/root/.ssh/git_rsa)
                                 Note: switching to 'aa2d8914354da2216e44a15ab5df1bbfabb30109'.
                                 You are in 'detached HEAD' state. You can look around, make experimental
                                 changes and commit them, and you can discard any commits you make in this
                                 state without impacting any branches by switching back to a branch.
                                 If you want to create a new branch to retain commits you create, you may
                                 do so (now or later) by using -c with the switch command. Example:
                                 git switch -c <new-branch-name>
                                 Or undo this operation with:
                                 git switch -
                                 Turn off this advice by setting config variable advice.detachedHead to false
                                 HEAD is now at aa2d891 Update landing page text
2021-09-15T20:40:06.941Z [INFO]: Successfully cleaned up Git credentials
2021-09-15T20:40:06.941Z [INFO]: # Checking for Git submodules at: /codebuild/output/src649041263/src/wai-platform/.gitmodules
2021-09-15T20:40:06.966Z [INFO]: # Retrieving environment cache...
2021-09-15T20:40:07.007Z [INFO]: # Retrieved environment cache
2021-09-15T20:40:07.007Z [INFO]: ---- Setting Up SSM Secrets ----
2021-09-15T20:40:07.008Z [INFO]: SSM params {"Path":"/amplify/dtq3eg2x08klj/dev/","WithDecryption":true}
2021-09-15T20:40:07.064Z [INFO]: # Ensuring NPM package '@aws-amplify/cli' is version: 'latest'
2021-09-15T20:40:13.829Z [INFO]: # Patching NPM package '@aws-amplify/cli' from 4.29.4 to 5.6.0...
2021-09-15T20:42:04.257Z [INFO]: # Done patching NPM package '@aws-amplify/cli'
2021-09-15T20:42:04.404Z [INFO]: # Retrieving cache...
2021-09-15T20:42:09.029Z [INFO]: # Extracting cache...
2021-09-15T20:42:17.481Z [INFO]: # Extraction completed
                                 # Starting phase: build
2021-09-15T20:42:34.254Z [INFO]: �[0mAmplify AppID found: dtq3eg2x08klj. Amplify App name is: waiplatform�[0m
2021-09-15T20:42:34.310Z [INFO]: �[0mBackend environment dev found in Amplify Console app: waiplatform�[0m
2021-09-15T20:42:35.120Z [INFO]: App not deployed yet.
2021-09-15T20:42:35.165Z [INFO]: App not deployed yet.
2021-09-15T20:42:35.178Z [INFO]: �[32m�[39m
                                 �[32mGraphQL schema compiled successfully.�[39m
                                 �[32mEdit your schema at /codebuild/output/src649041263/src/wai-platform/amplify/backend/api/waiplatform/schema.graphql or place .graphql files in a directory at /codebuild/output/src649041263/src/wai-platform/amplify/backend/api/waiplatform/schema�[39m
2021-09-15T20:42:35.183Z [INFO]: App not deployed yet.
2021-09-15T20:42:35.226Z [INFO]: �[0mSuccessfully generated models. Generated models can be found in /codebuild/output/src649041263/src/wai-platform/src�[0m
2021-09-15T20:42:35.228Z [WARNING]: - Fetching updates to backend environment: dev from the cloud.
2021-09-15T20:42:35.529Z [WARNING]: ✔ Successfully pulled backend environment dev from the cloud.
2021-09-15T20:42:35.556Z [WARNING]: ✖ There was an error initializing your environment.
2021-09-15T20:42:35.559Z [INFO]: �[31mFailed to pull the backend.�[39m
2021-09-15T20:42:35.561Z [INFO]: �[31mauth headless is missing the following inputParams userPoolId, webClientId, nativeClientId�[39m
2021-09-15T20:42:35.609Z [INFO]: �[0mError: auth headless is missing the following inputParams userPoolId, webClientId, nativeClientId�[0m
                                 �[0m    at ensureHeadlessParameters (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/src/provider-utils/awscloudformation/import/index.ts:1288:11)�[0m
                                 �[0m    at Object.headlessImport (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/src/provider-utils/awscloudformation/import/index.ts:1145:40)�[0m
                                 �[0m    at importedAuthEnvInit (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/src/provider-utils/awscloudformation/import/index.ts:922:18)�[0m
                                 �[0m    at processTicksAndRejections (internal/process/task_queues.js:97:5)�[0m
                                 �[0m    at updateConfigOnEnvInit (/root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/src/provider-utils/awscloudformation/index.js:50:72)�[0m
                                 �[0m    at /root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/src/index.js:306:22�[0m
2021-09-15T20:42:35.626Z [ERROR]: !!! Build failed
2021-09-15T20:42:35.626Z [ERROR]: !!! Non-Zero Exit Code detected
2021-09-15T20:42:35.626Z [INFO]: # Starting environment caching...
2021-09-15T20:42:35.626Z [INFO]: # Uploading environment cache artifact...
2021-09-15T20:42:35.697Z [INFO]: # Environment caching completed
Terminating logging...

Additional information

No response

@josefaidt
Copy link

josefaidt commented Sep 15, 2021

Hey @tomasff 👋 thanks for taking the time to file this and include those details! I was able to successfully reproduce the issue by taking the following steps:

  1. amplify init -y
  2. amplify import auth, choose some existing user pool
  3. Create sample Next.js SSG app
    // src/pages/_app.js
     import { Amplify } from 'aws-amplify'
     import { withAuthenticator, AmplifySignOut } from '@aws-amplify/ui-react'
     import config from '../aws-exports'
    
     Amplify.configure(config)
    
     function MyApp({ Component, pageProps }) {
       return (
         <main>
           <AmplifySignOut />
           <Component {...pageProps} />
         </main>
       )
     }
    
     export default withAuthenticator(MyApp)
  4. Create and push to git repository
  5. amplify add hosting > continuous deployments
  6. connect git repository to Hosting in the console
  7. after connecting, follow prompt to hit "Enter" to continue
  8. Observe build error out

image

Note: these values are present and available in team-provider-info.json https://github.com/josefaidt/amplify-imported-auth/blob/main/amplify/team-provider-info.json#L17-L20

Marking this as a bug 🙂

@josefaidt
Copy link

Hey @tomasff 👋 I found a workaround for this and it may require additional tweaking beyond my minimal reproduction, but at a high level we can replace amplifyPush --simple with our own headless init script. The main takeaway in the following git diff is that we are manually providing the imported auth information into the categories flag's value

https://github.com/josefaidt/amplify-imported-auth/commit/caa4a4874243c7fd3b1676ee72170f172276bcbf#diff-408f2ee929058c9e991c5af8d003eaded2c24e8616b94e48de84031a80397c0c

@tomasff
Copy link
Author

tomasff commented Sep 16, 2021

Thank you! Using the workaround allows my build to complete now 👍

@ocallarob
Copy link

Thank you so much @josefaidt!! This solved my build issue 🙌

@attilah
Copy link

attilah commented Sep 22, 2021

@ocallarob @tomasff could you try to define these variables and see if solves your problem, it looks like the documentation is outdated:
AMPLIFY_USERPOOL_ID
AMPLIFY_WEBCLIENT_ID
AMPLIFY_NATIVECLIENT_ID
AMPLIFY_IDENTITYPOOL_ID

Transferring to console as it seems to be a documentation issue on their part also missing docs for SIWA parameters.

@renebrandel renebrandel transferred this issue from aws-amplify/amplify-cli Sep 22, 2021
@aws-amplify aws-amplify deleted a comment from github-actions bot Sep 23, 2021
@siegerts siegerts added the transferred This issue was transferred from another Amplify project label Sep 23, 2021
@kierans
Copy link

kierans commented Oct 7, 2021

I think what's going on is a chicken and egg problem.

Having imported the Cognito details into my project (resulting in the details being added to team-provider-info.json) the amplify CLI tool can read those details which is the whole reason of using amplify import auth)

However to initialise the project so that the Congnito details can be read amplifyPush.sh needs the imported Cognito details passed - which are in the project configuration.

This is why the env var solution works as it breaks this loop, but also sucks because it means that whole feature of importing Cognito into Amplify is broken (assuming you're using CI/CD).

The solution, which is better IMO is to do what others have done. Have a custom "init script" based on amplifyPush.sh that parses team-provider-info.json and pass that JSON to the amplify init command like a lot of other examples have done (with the CATEGORIES env var)

CC #1271

@tjordanahp
Copy link

What worked for me was adding the Environment variables to

Please see here for all available environment variables.

image

@Jay2113 Jay2113 closed this as completed Feb 21, 2024
Copy link

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.

Copy link

This issue has been automatically locked.

@github-actions github-actions bot added the archived This issue has been locked. label Feb 21, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived This issue has been locked. backend-builds bug Something isn't working documentation transferred This issue was transferred from another Amplify project
Projects
None yet
Development

No branches or pull requests

9 participants