#Headless CI/CD fails in multiple account deployment

5 messages · Page 1 of 1 (latest)

craggy valve
#

Hello. I have set up separate prod and dev accounts in aws organisation. My CI/CD process in Github Actions is to initialize and pull dev (which has a new feature, for example, added table), then initialize prod and push to prod.

I am using the bash scripts from docs (https://docs.amplify.aws/cli/usage/headless/).

However, on amplify push, I'm getting the error 🛑 Could not load configuration.

Do you have any ideas why that could happen?

- name: Install amplify cli
        run: npm install -g @aws-amplify/cli

      - name: Configure AWS Credentials from DEV account
        uses: aws-actions/configure-aws-credentials@v2
        with:
          role-to-assume: arn:aws:iam::XXXX:role/GithubAccessDev
          aws-region: us-east-1

      - name: Initialise DEV env
        run: bash init-dev.sh

      - name: Pull DEV env
        run: bash pull-dev.sh

      - name: Configure AWS Credentials from PROD account
        uses: aws-actions/configure-aws-credentials@v2
        with:
          role-to-assume: arn:aws:iam::XXXX:role/GithubAccessProd
          aws-region: us-east-1

      - name: Initialise PROD env
        run: bash init-prod.sh

      - name: Push PROD env
        run: bash push-prod.sh
#

init script looks like this (env name is either dev or prod):

#!/bin/bash
set -e
IFS='|'

REACTCONFIG="{\
\"SourceDir\":\"/\",\
\"DistributionDir\":\"/\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"
AMPLIFY="{\
\"projectName\":\"SamphireApp\",\
\"appId\":\"XXXX\",\
\"envName\":\"dev\",\
\"defaultEditor\":\"code\"\
}"
FRONTEND="{\
\"frontend\":\"javascript\",\
\"framework\":\"react-native\",\
\"config\":$REACTCONFIG\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"

amplify init \
--amplify $AMPLIFY \
--frontend $FRONTEND \
--providers $PROVIDERS \
--yes
#

pull script looks like this:

#!/bin/bash
set -e
IFS='|'

REACTCONFIG="{\
\"SourceDir\":\"/\",\
\"DistributionDir\":\"/\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"
AMPLIFY="{\
\"projectName\":\"SamphireApp\",\
\"appId\":\"XXXX\",\
\"envName\":\"dev\",\
\"defaultEditor\":\"code\"\
}"
FRONTEND="{\
\"frontend\":\"javascript\",\
\"framework\":\"react-native\",\
\"config\":$REACTCONFIG\
}"
PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"

amplify pull \
--amplify $AMPLIFY \
--frontend $FRONTEND \
--providers $PROVIDERS \
--yes
#

push script:

#!/bin/bash
set -e
IFS='|'

CODEGEN="{\
\"generateCode\":true,\
\"codeLanguage\":\"javascript\",\
\"fileNamePattern\":\"src/graphql/**/*.js\",\
\"generatedFileName\":\"API\",\
\"generateDocs\":true\
}"

amplify push \
--codegen $CODEGEN \
--yes
--force
modern herald
#

Hey 👋 what does this workflow look like in practice? You shouldn't need to init, then pull each environment, but rather lean on git workflows such as opening and filing a PR to merge onto the "main" branch/"prod" environment, initialize the project in the runner, and push