Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
* Which Category is your question related to? *
Usage Question on Amplify Multienvs and CI workflow.
* What AWS Services are you utilizing? *
Aws Amplify/[email protected]
Frontend: Angular
* Provide additional details e.g. code snippets *
Hello,
So, I started to work with Amplify/CLI and I wanted (after creating my first environment) to update my CI. My CI is currently on Gitlab (custom runner with AWS policies from docker image node:carbon-alpine).
We're currently struggling about how to implement correctly the CI workflow. As we couldn't find proper examples of working CI with Gitlab and Amplify, we're asking out here.
Following my CI part for Amplify.
my scripts:
- envConfig=$(cat amplify/team-provider-info.json | jq .preprod | jq -R)
- amplify env import --name preprod --config $envConfig --awsInfo $config --yes
- amplify init --amplify $amplify --providers $providers --yes
- ng build --configuration=preprod --extract-css=false --no-progress --aot
my variables:
amplify: "{\"envName\":\"preprod\"}"
config: "{\"configLevel\":\"general\"}"
providers: "{\"awscloudformation\":$config}"
Here is the results, there is an error on the init.
$ envConfig=$(cat amplify/team-provider-info.json | jq .preprod | jq -R)
$ amplify env import --name preprod --config $envConfig --awsInfo $importConfig --yes
Successfully added environment from your project
$ amplify init --amplify $amplify --providers $providers --yes
Note: It is recommended to run this command from the root of your app directory
- Initializing your environment: preprod
✖ There was an error initializing your environment.
init failed
{ Error: ENOENT: no such file or directory, open '/root/.aws/credentials'
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Object.readFileSync (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/util.js:95:26)
at IniLoader.parseFile (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:6:47)
at IniLoader.loadFrom (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:56:30)
at Config.region (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/node_loader.js:98:36)
at Config.set (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/config.js:478:39)
at Config.<anonymous> (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/config.js:313:12)
at Config.each (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/util.js:484:32)
at new Config (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/config.js:312:19)
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/root/.aws/credentials' }
ERROR: Job failed: exit code 1
As there is no crendentials file, this error shouldn't appear.
Is there is something I am doing wrong? The documentation is not always clear on the CI/CD workflow.
Thanks in advance!
As you use general option for configLeve, so you need to make sure that aws credantials and config files exist and have the proper value. Try to run this script before you init your project:
#!/bin/bash
printf "[profile $1]\nregion=us-east-1\noutput=text" > ~/.aws/config
printf "[$1]\naws_access_key_id=$2\naws_secret_access_key=$3" > ~/.aws/credentials
printf "[default]\nregion=us-east-1\noutput=text" > /root/.aws/config
printf "[default]\naws_access_key_id=$2\naws_secret_access_key=$3" > /root/.aws/credentials
Thank you for your reply @eelzinaty, however I forgot to mention it but my AKSK are already defined as environment variables. It should check for my environment variables before checking for the file that purposely doesn't exist.
@Loghrenar Are you still stuck on this?
Hey @kaustavghosh06,
Yes, I'm still stuck on this point at the moment.
Most helpful comment
Thank you for your reply @eelzinaty, however I forgot to mention it but my AKSK are already defined as environment variables. It should check for my environment variables before checking for the file that purposely doesn't exist.