aws-amplify / aws-amplify/amplify-cli

amplify init fails when selecting `sso-session` entry in profile list: `Failed to get profile credentials, Unexpected token A in JSON at position 0`

Open
#12,777 3 comments 4 reactions 0 assignees View on GitHub
bug p3 platform
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### How did you install the Amplify CLI?

npm

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

v18.16.0

### Amplify CLI Version

12.0.3

### 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.

No, I'm not even able to init.

### Describe the bug

Tryin to use Amplify with AWS IAM Identity Center. `amplify init --debug` fails with the following error:

```
Failed to get profile credentials
Unexpected token A in JSON at position 0

Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/

ProfileConfigurationError: Failed to get profile credentials
at Object.getAwsConfig (/snapshot/repo/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/configuration-manager.js:939:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/amplify-provider-awscloudformation/lib/initializer.js:119:27)

Unexpected token A in JSON at position 0
ProcessCredentialsProviderFailure: Unexpected token A in JSON at position 0
at /snapshot/repo/build/node_modules/aws-sdk/lib/credentials/process_credentials.js:142:13
at ChildProcess.exithandler (node:child_process:411:7)
at ChildProcess.emit (node:events:513:28)
```

### Expected behavior

AWS nudges/recommends to use AWS IAM Identity Center. I would expect Amplify to be able to work with it. Is this not supported yet?

### Reproduction steps

The same behavior was reported by @josefaidt in https://github.com/aws-amplify/amplify-cli/issues/12174#issuecomment-1476927553

The issue says it's fixed, but I'm using the latest version and it's apparently not fixed.

Steps to reproduce:
1. `aws configure sso`
2. `amplify init`

This will fail with `Cannot read properties of undefined (reading 'accessKeyId')`.

3. Manually add `credential_process = aws sso login --profile ...` to `~/.aws/config`.
4. `amplify init` now redirects to SSO. After a successful login, the error above appears.

### Project Identifier

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

_No response_

### Before submitting, please confirm:

- [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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with `aws configure sso` and `amplify init`, then compare it with the `credential_process` setup in `~/.aws/config`. Start at the `configuration-manager.js` and `aws-sdk/lib/credentials/process_credentials.js` locations shown in the stack trace; done means selecting an SSO profile lets initialization complete without the JSON parsing error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
authentication, cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.