amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Amplify init doesn't work in CI workflow (Gitlab Runner)

Open Loghrenar opened this issue 7 years ago • 5 comments

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!

Loghrenar avatar May 03 '19 09:05 Loghrenar

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

eelzinaty avatar May 03 '19 11:05 eelzinaty

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 avatar May 03 '19 13:05 Loghrenar

@Loghrenar Are you still stuck on this?

kaustavghosh06 avatar May 24 '19 20:05 kaustavghosh06

Hey @kaustavghosh06,

Yes, I'm still stuck on this point at the moment.

Loghrenar avatar May 27 '19 08:05 Loghrenar

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.

github-actions[bot] avatar May 27 '21 08:05 github-actions[bot]