aws-amplify / aws-amplify/amplify-cli
CI workflow: Canonical 'Headless' usage of the CLI
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
**Which Category is your question related to?**
Headless usage of the CLI
While setting up CI workflow I followed [headless_configure_project](https://github.com/aws-amplify/amplify-cli/blob/master/packages/amplify-cli/sample-headless-scripts/headless_configure_project.sh) with a simple usecase of pushing the backend resources changes with `amplify push`.
Presented example:
```sh
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:
```sh
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:
```sh
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](https://aws-amplify.github.io/docs/cli/init#headless-usage-of-the-cli). **Another question:** why is `./amplify/backend/amplify-meta.json` is in default `.gitignore.`?
Contributor guide
Research direction
Start with sample-headless-scripts/headless_configure_project.sh and the headless-usage-of-the-cli documentation linked in the issue. Reproduce the configure project commands and inspect the handling of --frontend, amplify/.config/local-env-info.json, and amplify/backend/amplify-meta.json. Done means the documented CI workflow and the amplify-meta.json .gitignore guidance are clear and consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, react, shell, typescript
- Domain
- ci-cd, cli, cloud, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100