Amplify-cli: CLI: 4.23.0 - TypeError: Cannot read property 'provider' of undefined at Object.updateConfigOnEnvInit

Created on 8 Jul 2020  路  11Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
I'm currently trying to use the Amplify CLI headless in a custom CodeBuild setup. I'm not sure if I'm missing something here but I followed the steps I've seen and I'm getting the following the error in the log output.

153 | init failed
154 | TypeError: Cannot read property 'provider' of undefined
155 | at Object.updateConfigOnEnvInit (/usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/index.js:222:84)
156 | at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/amplify-category-function/lib/index.js:106:54
157 | at /usr/local/lib/node_modules/@aws-amplify/cli/node_modules/promise-sequential/index.js:16:18
158 | at process._tickCallback (internal/process/next_tick.js:68:7)
159

Amplify CLI Version
4.23.0

To Reproduce
I'm running this bash script as part of the build process.

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

echo $AWS_ACCESS_KEY_ID

AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"general\",\
\"useProfile\":false,\
\"accessKeyId\":$AWS_ACCESS_KEY_ID,\
\"secretAccessKey\":$AWS_SECRET_ACCESS_KEY,\
\"region\":\"us-east-1\"\
}"

AMPLIFY="{\
\"projectName\":\"dpportal\",\
\"envName\":\"staging\"\
}"

PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"

CODEGEN="{\
\"generateCode\":false,\
\"generateDocs\":false\
}"

amplify init \
--amplify $AMPLIFY \
--providers $PROVIDERS \
--codegen ${CODEGEN} \
--yes

amplify push

The $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY environment variables are added to the buildspec file which pulls those values from Secrets Manager.

Expected behavior
I expected the project to be initialized in order for me to deploy the stack and provision the resources.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment:
Also using this image to build the project
aws/codebuild/nodejs:10.14.1

critical-bug work-in-progress

Most helpful comment

Thanks for reporting this bug. We will triage and provide an update.

All 11 comments

I'm seeing the exact same and was just coming to report it. v4.23 came out yesterday and that's when the issue showed up for us. It doesn't seem to affect existing environments, only new environments in our CI/CD setup.

Workaround: I've pinned our build settings back to v4.22 and the build seems to be succeeding again.

image

Ah yes this worked for me as well. Guess the issue was introduced in this new version.

I'm seeing the exact same and was just coming to report it. v4.23 came out yesterday and that's when the issue showed up for us. It doesn't seem to affect existing environments, only new environments in our CI/CD setup.

Workaround: I've pinned our build settings back to v4.22 and the build seems to be succeeding again.

image

Thanks for reporting this bug. We will triage and provide an update.

@diondree
What are the amplify categories you added to your project?
What are the exact steps that leads to this issue?

@UnleashedMind I only have auth and a function added. This issue occurs when my CodeBuild process is triggered from Github.

This is the top part of my buildspec file where the issue occurs:

version: 0.2

env:
    secrets-manager:
        AWS_ACCESS_KEY_ID: AmplifyUser:AMPLIFY_SECRET_KEY_ID
        AWS_SECRET_ACCESS_KEY: AmplifyUser:AMPLIFY_ACCESS_KEY

phases:
  install:
    commands:
       - npm install -g @angular/[email protected]
       - npm install -g @aws-amplify/[email protected]
       - npm install
  pre_build:
    commands:
       - ./scripts/amplify.sh

As I mentioned it pulls the access key id and access key from secrets manager and then uses them in the amplify script (amplify.sh). This script is what I added as part of the original issue.

@diondree @codecadwallader could you share the "function" block of your amplify-meta.json file? Or if it contains sensitive information you can email it to [email protected]

@edwardfoyle I just sent the email with it

@edwardfoyle Ditto, sent.

Thanks for the great info @diondree @codecadwallader! We were able to reproduce and are working on a fix.

@jhockett That's awesome! You're very welcome

@aws-amplify/cli version 4.23.1 has just been released. If you experience the same issue on the latest version, please comment below.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kstro21 picture kstro21  路  3Comments

rehos picture rehos  路  3Comments

nicksmithr picture nicksmithr  路  3Comments

zjullion picture zjullion  路  3Comments

onlybakam picture onlybakam  路  3Comments