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

Cannot read property 'accessKeyId' of undefined, after latest update

Open adcanis opened this issue 2 years ago • 45 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

17.7.1

Amplify CLI Version

8.1.0

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

N/A

Amplify Categories

auth, api

Amplify Commands

pull, push, status

Describe the bug

After running aws-vault exec foo When performing an amplify command, error Failed to get profile: Cannot read property 'accessKeyId' of undefined presents itself.

If I remove aws-vault, and create a credentials file in my ~/.aws folder and add the credentials there, I get a different error: Name: ResourceNotFoundException : Message: User pool **-******-******** does not exist.

Expected behavior

The command(s) should work

Reproduction steps

Using AWS-VAULT

  1. aws-vault exec foo All commands there after present error

GraphQL schema(s)

# Put schemas below this line


Log output

# Put your logs below this line


Additional information

No response

adcanis avatar May 05 '22 16:05 adcanis

Hey @adcanis :wave: when using the AWS credentials and config files, can you confirm the region is set to the region which the Amplify app is deployed to?

josefaidt avatar May 05 '22 16:05 josefaidt

@josefaidt yes everything is there. I did run aws configure when removing aws-vault and using the credentials file. But there is not [default] listed in either file

adcanis avatar May 05 '22 17:05 adcanis

Hey @adcanis thanks for the clarification! In your amplify app's directory what Amplify CLI command are you executing to receive the "user pool ... does not exist" error? Is this on push?

josefaidt avatar May 05 '22 17:05 josefaidt

@josefaidt it doesn't matter what command, even status.

adcanis avatar May 05 '22 17:05 adcanis

@josefaidt I should add... if I run aws configure list I have a profile with no set profile name. This profile doesn't exist in my credentials or my config file but is listed when the command above is run. I think this may be the undefined item that is being referenced when error Failed to get profile: Cannot read property 'accessKeyId' of undefined is given when using aws-vault. What is the weird part, is when a credentials file was created and aws-vault was removed, it threw the cognito user pool error instead. Also, when aws configure list-profiles i only have the expected profiles My profile structure looks like so ` [profile foo] region=ca-central-1 output=json

[profile foo-dev] source_profile=foo region=ca-central-1 role_arn=arn:aws:iam::*********:role/app-foo-dev

This repeats for qa, prod `

adcanis avatar May 05 '22 17:05 adcanis

Hey @adcanis based on the error for "Cognito does not exist" it appears the Amplify CLI is successfully authenticating however is not able to find the resource in the specified account and region. If this is an existing project you have locally, is it possible the amplify/.config/local-aws-info.json file is pointing to a unintended profile for this environment?

{
  "dev": {
    "configLevel": "project",
    "useProfile": true,
    "profileName": "default"
  }
}

josefaidt avatar May 05 '22 22:05 josefaidt

@josefaidt thats just it. Everything is as it should be. Project works as expected, user pool authentication works and all that. I did a bit of updates to the schema today in regards to some resolvers, went to push, updated the cli and then this error

adcanis avatar May 05 '22 23:05 adcanis

Hey @adcanis can you confirm the Cognito User Pool ID shown in amplify/backend/amplify-meta.json at auth.<resource-name>.output.UserPoolId matches that of which we are seeing in the Console?

josefaidt avatar May 09 '22 18:05 josefaidt

@josefaidt my file inside the backend/auth/appname is parameters.json which shows the following { "authSelections": "userPoolOnly", "resourceName": "****************", "serviceType": "imported", "region": "ca-central-1", "authProvidersUserPool": [], "requiredAttributes": [], "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [ "Requires Lowercase", "Requires Uppercase", "Requires Numbers", "Requires Symbols" ], "mfaConfiguration": "OPTIONAL", "autoVerifiedAttributes": [ "email" ], "mfaTypes": [ "SMS Text Message", "TOTP" ] }

This was the order in my commands prior to the error:

amplify status no error was received. seen the update to the cli and ran the update before pushing the change should of pushed before

then I ran amplify api gql-compile without issue

went to run amplify push -y and received the first error about failed to get accesskeyId. Thats when I unset aws_vault, and exec'd with the credentials as usual. Ran amplify push -y again and received the same error. After unsetting my aws_vault again, I created the credentials file and added the credentials there which then threw the cognito error

adcanis avatar May 09 '22 18:05 adcanis

Hey @adcanis thanks for the clarification! I was looking to see if we potentially have a mismatch of Cognito ID's in our local copy versus what we're seeing in the AWS Console for Cognito. Do you also have a supplemental ~/.aws/config that specifies the intended regions for the profiles?

josefaidt avatar May 10 '22 20:05 josefaidt

So the ~/.aws/configlooks like this

`

[profile foo ] output=json region=ca-central-1

[profile foo-dev] source_profile=foo role_arn=arn:aws:iam::[AWS_ACCOUNT_NUMBER]:role/foo-dev-admin `

And so on with the subsequent profiles. Keep in mind, I wasn't using a credentials file until this error, I was using AWS-vault to set my credentials without issue.

adcanis avatar May 10 '22 20:05 adcanis

Hey @adcanis to clarify further are you attempting to use temporary credentials with the Amplify CLI?

josefaidt avatar May 10 '22 21:05 josefaidt

That's how I've always done it yes. At least with this project specifically

adcanis avatar May 10 '22 21:05 adcanis

I have the same issue. I try to pull and I get the Cannot read property 'accessKeyId' of undefined error! image

I tried to change the credentials with a new one by running amplify configure, and new credintials did not help either!

m98 avatar May 10 '22 22:05 m98

@m98 dis you update to the latest cli as well?

I've even deleted my ~/Library/Keychains/aws-vault.keychainand re-added everything and still get the same error

adcanis avatar May 10 '22 22:05 adcanis

Yes. I use version 8.1.0 which is the latest version on NPM.

m98 avatar May 10 '22 22:05 m98

For me, the problem was solved when I deleted the amplify directory and the aws-exports.js. (I think only deleting the amplify directory should be enough)

m98 avatar May 12 '22 15:05 m98

@m98 Good to know. I will try that today and do a pull. Just to confirm, are you running aws-vault to set temp credentials or are you using a credentials file?

adcanis avatar May 12 '22 15:05 adcanis

I ran amplify init then enter the credentials (previously I created that credential by running amplify configure)

m98 avatar May 12 '22 15:05 m98

@josefaidt @m98 Just wanted to say thanks for all the help. The resolution seems to be to remove the amplify directory and aws-exports.js file as @m98 mentioned. In my case I did not init, but rather pulled the existing project in.

adcanis avatar May 13 '22 12:05 adcanis

Hey @adcanis and @m98 that is an interesting find. Are you able to capture the git diff of amplify/.config/project-info.json? I'm curious in knowing if we can reproduce this behavior and permanently resolve from our end

josefaidt avatar May 13 '22 19:05 josefaidt

@josefaidt ill take a look. Funny enough this has opened up an entire other issue. I removed the folder and exports file as stated and ran amplify pull --appId ******** --envName *** no more credentials issue. amplify status doesn't show the errors and AWS-vault seems to be setting credentials just fine.

I now get a 400 error on my cognito and all users can't log in. Nothing has changed. This was an imported user pool if that matters.

Edit to add** I created a new user, and also a new user pool just to see what would happen if I removed auth and imported a new one. User can follow authentication the first time, but once logged out can't log back in. Error 400. Again this is NOW only and an issue after the step above

adcanis avatar May 13 '22 19:05 adcanis

amplify status not getting any error

amplify push i am getting same error

Failed to get profile: Cannot read property 'accessKeyId' of undefined

vkanagarajan avatar May 16 '22 06:05 vkanagarajan

Hey @adcanis thank you for clarifying and I'm glad to hear that you're able to mitigate the issue. For the authentication issue would you mind creating a separate bug report for that? Does the aws-exports.js file still point to the older auth resource?

@vkanagarajan can you paste the contents of amplify/.config/local-aws-info.json omitting any sensitive information? For example, my sample application's file looks like:

{
  "dev": {
    "configLevel": "project",
    "useProfile": true,
    "profileName": "default"
  }
}

josefaidt avatar May 16 '22 20:05 josefaidt

@josefaidt ill open a new bug report on the cognito front. It appears to be coming from the setTOTP and prefferedMFA function. aws-exports is correct depending on what auth I bring in to correct the issue. Thanks for the help!

adcanis avatar May 16 '22 20:05 adcanis

Can confirm that deleting the amplify directory and then running amplify pull --appId ******** --envName *** to grab my backend files again fixed the issue for me with no weird side-effects. I didn't need to delete my aws-exports.js.

Booligoosh avatar May 17 '22 02:05 Booligoosh

amplify/.config/local-aws-info.json file i am having this same code { "dev": { "configLevel": "project", "useProfile": true, "profileName": "default" } }

vkanagarajan avatar May 17 '22 09:05 vkanagarajan

@vkanagarajan have you tried deleting your amplify directory, the aws-exports file from src and running amplify pull --appID ***** --envName ****?

adcanis avatar May 17 '22 09:05 adcanis

I've tried deleting everything, running amplify pull to get a fresh copy of the backend, and any subsequent push operation results in "Failed to get profile: Cannot read property 'accessKeyId' of undefined". Running latest Amplify CLI on Mac OS X.

scottbw avatar May 17 '22 12:05 scottbw

@scottbw have you ran unset AWS_VAULT followed by aws-vault clear in-order to remove any temp credentials and session?

Edit: I just ran a amplify push -y and that did NOT return the issue

adcanis avatar May 17 '22 12:05 adcanis