Which Category is your question related to?
Headless usage of the CLI
While setting up CI workflow I followed headless_configure_project with a simple usecase of pushing the backend resources changes with amplify push
.
Presented example:
REACTCONFIG="{\
\"SourceDir\":\"src\",\
\"DistributionDir\":\"dist\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\",\
\"accessKeyId\":\"$AWS_ACCESS_KEY_ID\",\
\"secretAccessKey\":\"$AWS_SECRET_ACCESS_KEY\",\
\"region\":\"ap-southeast-1\"\
}"
AMPLIFY="{\
\"projectName\":\"headlessProjectName\",\
\"defaultEditor\":\"code\"\
}"
FRONTEND="{\
\"frontend\":\"javascript\",\
\"framework\":\"react\",\
\"config\":$REACTCONFIG\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
./node_modules/.bin/amplify configure project --amplify $AMPLIFY --frontend $FRONTEND --providers $PROVIDERS
fails with SyntaxError: Unexpected end of JSON input
.
Changing $FRONTEND to project_config.json exact structure also fails:
JAVASCRIPT_CONFIG="{\
\"framework\":\"react\",\
\"config\":$REACTCONFIG\
}"
FRONTEND="{\
\"projectName\":\"magicproj\",\
\"version\":\"2.0\",\
\"frontend\":\"javascript\",\
\"javascript\":$JAVASCRIPT_CONFIG,\
\"providers\":[\"awscloudformation\"]\
}"
Not specifying --frontend $FRONTEND
would have this error gone, now CLI would complain about non-existence of ./amplify/.config/local-env-info.json
and ./amplify/backend/amplify-meta.json
(using default amplify initialized project with default .gitignore).
After committing ./amplify/backend/amplify-meta.json
to git and generating ./amplify/.config/local-env-info.json
it does work with:
REACTCONFIG="{\
\"SourceDir\":\"src\",\
\"DistributionDir\":\"dist\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":false,\
\"accessKeyId\":\"$AWS_ACCESS_KEY_ID\",\
\"secretAccessKey\":\"$AWS_SECRET_ACCESS_KEY\",\
\"region\":\"ap-southeast-1\"\
}"
AMPLIFY="{\
\"projectName\":\"magicproj\",\
\"defaultEditor\":\"code\"\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
echo '{"projectPath": "'"$(pwd)"'","defaultEditor":"code","envName":"dev"}' > ./amplify/.config/local-env-info.json
./node_modules/.bin/amplify configure project --amplify $AMPLIFY --providers $PROVIDERS --yes
./node_modules/.bin/amplify env pull --yes
./node_modules/.bin/amplify push --yes
My question is: Am I doing a right thing here? It looks a bit cumbersome and I wasn't actually able to find any documentation on this except headless-usage-of-the-cli. Another question: why is ./amplify/backend/amplify-meta.json
is in default .gitignore.
?
@ambientlight
you might want to take a look at some sample headless scripts out here - https://github.com/aws-amplify/amplify-cli/blob/master/packages/amplify-cli/sample-headless-scripts/headless_push.sh
@kaustavghosh06: yeah I have followed them. I wonder if scripts for configure project
are outdated.
we can store all the jsons needed by configure projects
into ci_config.json
in the repository and then feed it to amplify configure project
with jq
, but isn't it's what should be done on amplify side, it feels a bit strange feeding jsons to cli, so I wonder if this is the only way to do this?
@ambientlight Thanks for the feedback. What we could probably do is introduce a flag -c
which accepts a config file path and read the JSON from the that file. Something like amplify push -c <file-path>
. Do you think that would be a better approach?
@kaustavghosh06: yes, that would be an improvement definitely.
Also another possibility would be to have all minimal configuration consolidated in /amplify/.config/project-config.json
. Then we won't need to pass anything to amplify push
at all.
Say without AWSCLOUDFORMATIONCONFIG
set cli can use AWS_PROFILE or AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY , AWS_DEFAULT_REGION environment variables.
Most helpful comment
@kaustavghosh06: yes, that would be an improvement definitely.
Also another possibility would be to have all minimal configuration consolidated in
/amplify/.config/project-config.json
. Then we won't need to pass anything toamplify push
at all.Say without
AWSCLOUDFORMATIONCONFIG
set cli can use AWS_PROFILE or AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY , AWS_DEFAULT_REGION environment variables.