Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 tasks done
adcanis opened this issue May 5, 2022 · 55 comments
Closed
5 tasks done

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

adcanis opened this issue May 5, 2022 · 55 comments
Labels
feature-request Request a new feature p3 pending-review Pending review from core-team platform Issues tied to the general CLI platform

Comments

@adcanis
Copy link

adcanis commented May 5, 2022

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • 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

@josefaidt josefaidt added platform Issues tied to the general CLI platform pending-triage Issue is pending triage labels May 5, 2022
@josefaidt
Copy link
Contributor

Hey @adcanis 👋 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?

@adcanis
Copy link
Author

adcanis commented May 5, 2022

@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

@josefaidt
Copy link
Contributor

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?

@adcanis
Copy link
Author

adcanis commented May 5, 2022

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

@adcanis
Copy link
Author

adcanis commented May 5, 2022

@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
`

@josefaidt
Copy link
Contributor

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"
  }
}

@adcanis
Copy link
Author

adcanis commented May 5, 2022

@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

@josefaidt
Copy link
Contributor

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 josefaidt added the pending-response Issue is pending response from the issue author label May 9, 2022
@adcanis
Copy link
Author

adcanis commented May 9, 2022

@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

@josefaidt
Copy link
Contributor

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?

@adcanis
Copy link
Author

adcanis commented May 10, 2022

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.

@josefaidt
Copy link
Contributor

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

@adcanis
Copy link
Author

adcanis commented May 10, 2022

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

@m98
Copy link

m98 commented May 10, 2022

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!

@adcanis
Copy link
Author

adcanis commented May 10, 2022

@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

@m98
Copy link

m98 commented May 10, 2022

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

@m98
Copy link

m98 commented May 12, 2022

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)

@adcanis
Copy link
Author

adcanis commented May 12, 2022

@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?

@m98
Copy link

m98 commented May 12, 2022

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

@adcanis
Copy link
Author

adcanis commented May 13, 2022

@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 adcanis closed this as completed May 13, 2022
@josefaidt
Copy link
Contributor

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 josefaidt reopened this May 13, 2022
@josefaidt josefaidt added pending-close-response-required and removed pending-response Issue is pending response from the issue author labels May 13, 2022
@josefaidt
Copy link
Contributor

Hey @vkanagarajan I was able to reproduce this if I point my profileName in amplify/.config/local-aws-info.json to a profile name that does not exist on my machine:

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

Can you confirm the profile default exists within your AWS configuration at ~/.aws/credentials?

@josefaidt josefaidt added the pending-response Issue is pending response from the issue author label May 19, 2022
@vkanagarajan
Copy link

I have fixed this issue created new user and added the access and secret key

@m98
Copy link

m98 commented May 20, 2022

@josefaidt In my case, I guess maybe the AWS Toolkit for my IDE caused this! With that you can rename the credintials!

It's good to know if other people in this thread who had this issue were also using AWS Toolkit!

@josefaidt
Copy link
Contributor

Hey @vkanagarajan glad to hear you're back up and running, and thanks @m98 for chiming in here! I'm glad to hear you've found value out of this thread!

Given the issue is now resolved I will close this for now, however if this issue reappears please reply back to this thread and we can re-open to investigate further 🙂

@josefaidt josefaidt added question General question and removed pending-response Issue is pending response from the issue author pending-triage Issue is pending triage labels May 25, 2022
@slim-elephant
Copy link

I faced the same issue, sorted out by doing the following.

Under Amplify -> .config -> local-aws-info.json profile name was defined as ABC whereas new profile I created did not match the name. Simple went to ~/Users/username/.aws/ and changed profile name in credentials and config file to match the project. Or you can do the other way around if profile is being used by multiple projects or define a new profile with matching name,

@armenr
Copy link

armenr commented Aug 29, 2022

@josefaidt - This shouldn't be closed!

I have wrapped Amplify into a pretty complex setup, and everything has been working as expected. I am externalizing some specifics around CI/CD (and CI/CD steps), and in my EXTERNAL CI/CD system (as well as on my local machine, outside of my github repo - in some empty folder), I am getting the following errors.

Scenario:

  1. There is a named AWS profile configured on the system where amplify runs (my local machine and/or CI/CD VM) with name armen-dev
  2. There is an existing backend named "develop" (verified valid)
  3. There is an existing Amplify App with ID "" (verified valid)

Reproduce:

  1. mkdir some-test
  2. cd some-test

Command permutation 1

  1. amplify pull --providers '{"awscloudformation":'{"develop":'{"configLevel":"project","useProfile":true,"profileName":"armen-dev"}'}'}' --amplify '{"appId":"REDACTED","envName":"develop"}' --yes

Error Result:

Error in the command line parameter for awscloudformation configuration.
Failed to pull the backend.
🛑 project level config set useProfile to false, but access key or region is missing.
Error: project level config set useProfile to false, but access key or region is missing.
    at normalizeInputParams (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/configuration-manager.js:239:15)
    at Object.init (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/configuration-manager.js:90:3)
    at Object.run (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/attach-backend.js:97:32)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Object.attachBackend (/snapshot/repo/build/node_modules/amplify-provider-awscloudformation/lib/index.js:210:3)
    at async queryProvider (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/attach-backend-steps/a10-queryProvider.js:31:5)
    at async attachBackend (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/attach-backend.js:38:9)
    at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/commands/pull.js:70:9)
    at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:292:9)
    at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
    at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
    at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:165:13)

Command permutation 2

  1. amplify pull --providers '{"awscloudformation":'{"configLevel":"project","useProfile":true,"profileName":"stelth-dev"}'}' --amplify '{"appId":"REDACTED","envName":"develop"}' --yes

Error Result:

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

Observations

I know for sure the region and credentials are all set up correctly because I'm doing it this way:

aws configure --profile "$AWS_APP_PROFILE_NAME" set aws_access_key_id "$AWS_ACCESS_KEY_ID"
aws configure --profile "$AWS_APP_PROFILE_NAME" set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
aws configure --profile "$AWS_APP_PROFILE_NAME" set region $AWS_REGION

AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY are injected as env vars in my CI/CD pipeline
AWS_APP_PROFILE_NAME is also injected as an env var

I know it's working because I get the values back when I log them/echo them in the build pipeline

@makyinmars
Copy link

makyinmars commented Sep 15, 2022

I'm using @aws-amplify/cli v10.0.0. I did amplify init and then I selected AWS access keys instead of AWS profile and finally I inserted my accessKeyId, secretAccessKey and region when asked on the cli.

@josefaidt josefaidt reopened this Sep 19, 2022
@josefaidt josefaidt added feature-request Request a new feature and removed question General question labels Sep 19, 2022
@josefaidt
Copy link
Contributor

Hey folks I've reopened this issue as a feature request to potentially expose a --profile flag when using headless CLI locally, as this is failing due to the lack of a default profile.

@josefaidt josefaidt added the pending-review Pending review from core-team label Sep 19, 2022
@nickvankleeck
Copy link

nickvankleeck commented Sep 23, 2022

The same bug now appears when running 'amplify init -y' as part of performing the steps in Module 1 of the AWS tutorial "Deploy a Web Application on AWS Amplify" here: https://aws.amazon.com/getting-started/guides/deploy-webapp-amplify/module-one/.

@ykethan ykethan added the p3 label Oct 31, 2022
@ehounder
Copy link

I get this same error with this same tutorial - after creating a new user with all privileges and new accessKeyID:

`Project information
| Name: amplifyapp
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: react
| Source Directory Path: src
| Distribution Directory Path: build
| Build Command: npm run-script build
| Start Command: npm run-script start

Using default provider awscloudformation
Failed to get profile: Cannot read property 'accessKeyId' of undefined
xxxyyy@zzzz-MacBook-Pro-2 amplify-app %`

@letsbelopez
Copy link
Contributor

I'm getting this error in CI/CD pipeline running amplify-dev pull.

I have configured my default profile credentials using aws configure set command and in my --providers flag I selected to use a profile and use one called default.

@mguja-fcc
Copy link

I am getting the same error ⠋ Fetching AWS Amplify Console domains🛑 Failed to get profile credentials
Cannot read property 'accessKeyId' of undefined when upgraded my Aplify CLI from version 7.6.21 to 10.8.0

@pavellazar
Copy link
Contributor

Hi @armenr, it looks that in your example you have some extra quotes after the "awscloudformation": argument, this command should work for you:
amplify pull --providers '{"awscloudformation":{"configLevel":"project","useProfile":true,"profileName":"stelth-dev"}}' --amplify '{"appId":"REDACTED","envName":"develop"}' --yes

We already support passing profile name as the profileName under the awscloudformation as documented here: https://docs.amplify.aws/cli/usage/headless/#--providers.

Nonetheless, this error message is terribly misleading, and we need to improve how we parse the command line arguments as a separate task.

As a workaround to generate the correct syntax, I can suggest using the scripts from our documentation page and add set +x after set -e command to print the executed command after it's assembled.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@DaichiShirakawa
Copy link

DaichiShirakawa commented Apr 19, 2023

Hi guyz, I melt 3hours for this fucking problem:

$ amplify -v
11.0.5

$ amplify status # same for amplify publish

...

🛑 Failed to get profile credentials
Cannot read property 'accessKeyId' of undefined

And finally resolved it as below procedure with my profile set in ~/.aws/credentials:

$ amplify configure project
# > AWS Profile setting
# > Update AWS Profile
# > AWS profile
# > (Select your profile)

@righteousgambit
Copy link

ok - I'm using an SSO profile to deploy. I run amplify init using a named profile appdeploy. No matter whether I call the --profile flag when I run amplify init and select appdeploy as the aws profile or not...it believes the access_key_id is "undefined". However, when I change the name of that profile to default...all of a sudden it works.

There is clearly an bug for (at least) amplify init whereby under certain conditions, it won't recognize any profile other than default.

@Audiopolis
Copy link

Definitely not fixed.

@codenimble
Copy link

Ugh just ran into this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request a new feature p3 pending-review Pending review from core-team platform Issues tied to the general CLI platform
Projects
None yet
Development

No branches or pull requests