Closed edmond-io closed 3 years ago
@edmond-io Few questions here
ap-northeast-1
?@SwaySway
$ amplify init
Note: It is recommended to run this command from the root of your app directory
? Do you want to use an existing environment? Yes
? Choose the environment you would like to use: prod
? Choose your default editor: IntelliJ IDEA
Using default provider awscloudformation
For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use default
✔ Initialized provider successfully.
The previously imported 'stockappxxxxx' auth resource was imported from 'undefined' region and the new environment's region is: 'ap-northeast-1', import a new resource to finish the creation of the new environment.
✔ Select the User Pool you want to import: · ap-northeast-1_49xxxxxx
✔ Only one Web app client found: 'web-client' was automatically selected.
✔ Only one Native app client found: 'native-app' was automatically selected.
✔ Federated identity providers are not configured, no OAuth configuration needed.
Initialized your environment successfully.
Your project has been successfully initialized and connected to the cloud!
Some next steps:
"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify add <category>" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify console" to open the Amplify Console and view your project status
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
Pro tip:
Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything
amplify/backend/backend-config.json
{
"function": "...",
"hosting":"...",
"auth": {
"stockappxxxxx": {
"service": "Cognito",
"serviceType": "imported",
"providerPlugin": "awscloudformation",
"dependsOn": [],
"customAuth": false
}
},
"api":"..."
}
@edmond-io Are you using your own custom amplifyPush script? If so could you provide the script you are using.
@SwaySway This is the custom amplifyPush script.
#!/usr/bin/env bash
set -e
IFS='|'
help_output () {
echo "usage: amplify-push <--environment|-e <name>> <--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
echo "# Initial value of ENV: ${ENV}, AWS_BRANCH: ${AWS_BRANCH}, USER_BRANCH: ${USER_BRANCH}, POSITIONAL ${POSITIONAL[@]}"
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
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
Hey, guys @edmond-io @SwaySway. I faced the same problem, any solutions found? It would be really helpful. Thanks!
Ok, the solution: restore/create parameters.json
file in amplify/backend/auth/<APP_PREFIX><GUID>
.
File content:
{
"authSelections": "userPoolOnly",
"resourceName": "<APP_PREFIX><GUID>",
"serviceType": "imported",
"region": "<NEEDED_REGION>"
}
In the log above
@viraxslot This didn't work for me :( I can't seem to build my app.
Hey y'all :wave: are you still experiencing this issue with the latest version of the Amplify CLI?
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels for those types of questions.
Describe the bug Unable to build through the amplify console when the auth resource is imported from an existing Congito User Pool and Identity Pool. It works perfectly fine when running in local with amplify push.
The error message is:
The auth configuration during amplify import set up:
Amplify CLI Version 4.42.0
Log output