aws-amplify / aws-amplify/amplify-hosting

Build Failure - Incorrect STACK_INFO - Imported Auth (amplifyPush script)

Open
#1,716 0 comments 0 reactions 0 assignees View on GitHub
backend-builds
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

Original error:

> auth headless init is missing the following inputParams userPoolId, webClientId, nativeClientId

I have almost resolved it with the common solution from [https://github.com/aws-amplify/amplify-console/issues/206#issuecomment-660498668](url) which uses the script below. The solution works for my first environment (dev), but when I try to deploy another (which imports a different cognito user pool) I get this error:

> The previously configured Web app client cannot be found

**The stack info retrieved from the script contains the info for the dev environment.**

Am I missing something?

**Build Output**

```
2021-03-31T22:21:14.134Z [INFO]: # Executing command: ./amplifyPush.sh
2021-03-31T22:21:14.139Z [INFO]: # Getting Amplify CLI Cloud-Formation stack info from environment cache
2021-03-31T22:21:14.173Z [INFO]: # Start initializing Amplify environment: qa
2021-03-31T22:21:14.174Z [INFO]: STACKINFO={
"awscloudformation": {
"AuthRoleName": "amplify-xxxxxx-qa-xxxxx-authRole",
"UnauthRoleArn": "arn:aws:iam::xxxx:role/xxxxxx-xxxxxx-qa-xxxxx-unauthRole",
"AuthRoleArn": "arn:aws:iam::xxxxx:role/xxxxx-xxxxxxxx-qa-xxxx-authRole",
"Region": "us-east-1",
"DeploymentBucketName": "amplify-xxxxxxxxxxx-qa-xxxxx-deployment",
"UnauthRoleName": "amplify-xxxxxxxxxxxxl-qa-xxxxxx-unauthRole",
"StackName": "amplify-xxxxxxxxxxx-qa-xxxxxxxxx",
"StackId": "arn:aws:xxxxxxxxxxxxxxxxxxx",
"AmplifyAppId": "xxxxxxxxxxxxx"
},
"categories": {
"auth": {
"xxxxxxxxxd1e27fda": {
"userPoolId": "us-east-1_xxxxxxxxxx",
"userPoolName": "xxxxxxxxxxxxxx_user_pool-dev",
"webClientId": "xxxxxxxxxxxxxxxxxxxxxx",
"nativeClientId": "xxxxxxxxxxxxxxxxxxxxxx",
"identityPoolId": "us-east-1:fxxxxxxxxxxxxxxxxxxxxxx",
"identityPoolName": "xxxxxxxxxxxxx_identitypool_73a8b95d__dev",
"authRoleArn": "arnxxxxxx-dev--xxxxx",
"authRoleName": "xxxxxxxxxxxxx-**dev**-xxxxxxx-authRole",
"unauthRoleArn": "arn:xxxxxx-xxxxxxxxx-xxxxxxxx",
"unauthRoleName": "xxxxxxxxx-xxxxxxx-xxxxxx-xxxxx"
}
}
}
}
# Importing Amplify environment: qa (amplify env import)
2021-03-31T22:21:15.542Z [INFO]: Successfully added environment from your project
2021-03-31T22:21:15.613Z [INFO]: #Testing1
# Initializing existing Amplify environment: qa (amplify init)
2021-03-31T22:21:19.096Z [INFO]: Note: It is recommended to run this command from the root of your app directory
2021-03-31T22:21:26.645Z [WARNING]: - Initializing your environment: qa
2021-03-31T22:21:26.886Z [WARNING]: ✔ Initialized provider successfully.
2021-03-31T22:21:27.428Z [WARNING]: ✖ There was an error initializing your environment.
2021-03-31T22:21:27.440Z [INFO]: Error: The previously configured Web app client cannot be found.
 at 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:1173:11)
 at processTicksAndRejections (internal/process/task_queues.js:97:5)
 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:903:12)
 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)
 at /root/.nvm/versions/node/v12.21.0/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-auth/src/index.js:300:22
2021-03-31T22:21:27.456Z [ERROR]: !!! Build failed
2021-03-31T22:21:27.456Z [ERROR]: !!! Non-Zero Exit Code detected
```

**amplifyPush.sh**
```
set -e
IFS='|'

help_output () {
echo "usage: amplify-push <--environment|-e > <--simple|-s>"
echo " --environment The name of the Amplify environment to use"
echo " --simple Optional simple flag auto-includes stack info from env cache"
exit 1
}

init_env () {
ENV=$1
AMPLIFY=$2
PROVIDERS=$3
CODEGEN=$4
AWSCONFIG=$5
CATEGORIES=$6

echo "# Start initializing Amplify environment: ${ENV}"
if [[ -z ${STACKINFO} ]];
then
echo "# Initializing new Amplify environment: ${ENV} (amplify init)"
[[ -z ${CATEGORIES} ]] && amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --yes || amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --categories ${CATEGORIES} --yes
echo "# Environment ${ENV} details:"
amplify env get --name ${ENV}
else
echo "STACKINFO="${STACKINFO}
echo "# Importing Amplify environment: ${ENV} (amplify env import)"
amplify env import --name ${ENV} --config "${STACKINFO}" --awsInfo ${AWSCONFIG} --yes;
echo "# Initializing existing Amplify environment: ${ENV} (amplify init)"
[[ -z ${CATEGORIES} ]] && amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --yes || amplify init --amplify ${AMPLIFY} --providers ${PROVIDERS} --codegen ${CODEGEN} --categories ${CATEGORIES} --yes
echo "# Environment ${ENV} details:"
amplify env get --name ${ENV}
fi
echo "# Done initializing Amplify environment: ${ENV}"
}

ENV=""
IS_SIMPLE=false
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case ${key} in
-e|--environment)
ENV=$2
shift
;;
-r|--region)
REGION=$2
shift
;;
-s|--simple)
IS_SIMPLE=true
shift
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"

# if no provided environment name, use default env variable, then user override
if [[ ${ENV} = "" ]];
then
ENV=${AWS_BRANCH}
fi

if [[ ${USER_BRANCH} != "" ]];
then
ENV=${USER_BRANCH}
fi

# strip slashes, limit to 10 chars
ENV=$(echo ${ENV} | sed 's;\\;;g' | sed 's;\/;;g' | cut -c -10)

# Check valid environment name
if [[ -z ${ENV} || "${ENV}" =~ [^a-zA-Z0-9\-]+ ]] ; then help_output ; fi

AWSCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\",\
\"AmplifyAppId\":\"${AWS_APP_ID}\"\
}"
AMPLIFY="{\
\"envName\":\"${ENV}\",\
\"appId\":\"${AWS_APP_ID}\"\
}"
PROVIDERS="{\
\"awscloudformation\":${AWSCONFIG}\
}"
CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"
CATEGORIES=""
if [[ -z ${AMPLIFY_FACEBOOK_CLIENT_ID} && -z ${AMPLIFY_GOOGLE_CLIENT_ID} && -z ${AMPLIFY_AMAZON_CLIENT_ID} ]]; then
CATEGORIES=""
AUTHCONFIG="{\
\"userPoolId\":\"${AMPLIFY_USERPOOL_ID}\",\
\"webClientId\":\"${AMPLIFY_WEBCLIENT_ID}\",\
\"nativeClientId\":\"${AMPLIFY_NATIVECLIENT_ID}\"\
\"identityPoolId\":\"${AMPLIFY_IDENTITYPOOL_ID}\"\
}"
CATEGORIES="{\
\"auth\":$AUTHCONFIG\
}"
else
AUTHCONFIG="{\
\"facebookAppIdUserPool\":\"${AMPLIFY_FACEBOOK_CLIENT_ID}\",\
\"facebookAppSecretUserPool\":\"${AMPLIFY_FACEBOOK_CLIENT_SECRET}\",\
\"googleAppIdUserPool\":\"${AMPLIFY_GOOGLE_CLIENT_ID}\",\
\"googleAppSecretUserPool\":\"${AMPLIFY_GOOGLE_CLIENT_SECRET}\",\
\"amazonAppIdUserPool\":\"${AMPLIFY_AMAZON_CLIENT_ID}\",\
\"amazonAppSecretUserPool\":\"${AMPLIFY_AMAZON_CLIENT_SECRET}\"\
}"
CATEGORIES="{\
\"auth\":$AUTHCONFIG\
}"
fi
# Handle old or new config file based on simple flag
if [[ ${IS_SIMPLE} ]];
then
echo "# Getting Amplify CLI Cloud-Formation stack info from environment cache"
export STACKINFO="$(envCache --get stackInfo)"
init_env ${ENV} ${AMPLIFY} ${PROVIDERS} ${CODEGEN} ${AWSCONFIG} ${CATEGORIES}
echo "# Store Amplify CLI Cloud-Formation stack info in environment cache"
STACKINFO="$(amplify env get --json --name ${ENV})"
envCache --set stackInfo ${STACKINFO}
echo "STACKINFO="${STACKINFO}
else
# old config file, above steps performed outside of this script
init_env ${ENV} ${AMPLIFY} ${PROVIDERS} ${CODEGEN} ${AWSCONFIG} ${CATEGORIES}
fi
```

**Output from auth import (appears correct)**
```
✔ What type of auth resource do you want to import? · Cognito User Pool and Identity Pool
✔ Select the User Pool you want to import: · us-east-1_xxxxxxxxx
✔ Only one Web app client found: 'xxxxxxx_app_clientWeb' was automatically selected.
✔ Only one Native app client found: 'xxxxxx_app_client' was automatically selected.
✔ Federated identity providers are not configured, no OAuth configuration needed.
✔ Only one Identity Pool resource found: 'xxxxxxxx_identitypool_xxxxxxx__qa' (us-east-1:xxxxxxxxxx) was automatically selected.
```

Contributor guide

Open the contributing guide

Research direction

Start with amplifyPush.sh, especially the envCache --get stackInfo path and the amplify env import/init calls. Compare the cached STACKINFO for dev with the qa values shown in the build output, then trace the reported auth import entry point in amplify-category-auth. Done means the qa deployment imports its own Cognito clients without the previously configured Web app client error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, shell
Domain
authentication, ci-cd, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.