Describe the bug
Amplify Init fails after selecting existing profile.
To Reproduce
Steps to reproduce the behavior:
amplify init
Do you want to use a profile?
Expected behavior
Amplify is initialized without a crash error message.
Screenshots
See CLI output below.
Desktop (please complete the following information):
Additional context
This was reported long ago, over here:
https://github.com/aws-amplify/amplify-cli/issues/191#issuecomment-507046590
CLI output:
$ amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project nulfi.com
? Enter a name for the environment dev
? Choose your default editor: Visual Studio Code
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using 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
For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html
? Do you want to use an AWS profile? No
? accessKeyId: **********
? secretAccessKey: ********************
? region: us-west-2
✖ Root stack creation failed
init failed
TypeError: Cannot redefine property: default
at Function.defineProperty (<anonymous>)
at /Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:11:14
at Array.forEach (<anonymous>)
at IniLoader.parseFile (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/shared-ini/in
i-loader.js:8:26)
at IniLoader.loadFrom (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:56:30)
at Config.region (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/node_loader.js:98:36)
at Config.set (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/config.js:477:39)
at Config.<anonymous> (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/config.js:312:12)
at Config.each (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/util.js:507:32)
at new Config (/Users/jkgrant/.nvm/versions/node/v12.3.1/lib/node_modules/@aws-amplify/cli/node_modules/aws-sdk/lib/config.js:311:19)
I found the source of my problem. The code linked below attempts to add non-unique properties for profileName
. My ~/.aws/config
file contained entries called [default]
and [profile default]
, which causes the symptom.
https://github.com/aws/aws-sdk-js/blob/master/lib/shared-ini/ini-loader.js#L10-L11
function parseFile(filename, isConfig) {
var content = AWS.util.ini.parse(AWS.util.readFileSync(filename));
var tmpContent = {};
Object.keys(content).forEach(function(profileName) {
var profileContent = content[profileName];
profileName = isConfig ? profileName.replace(/^profile\s/, '') : profileName;
Object.defineProperty(tmpContent, profileName, { /*** TROUBLE ***/
value: profileContent,
enumerable: true
});
});
return tmpContent;
}
This code should take more care in case ~/.aws/config
is malformed. I don't know if I caused this with manual edits or using an old version of aws configure
could have caused it.
I removed one of my entries [default]
and now amplify init
works.
Thank you @cyrfer, your comment saved me from hours of head-scratching.
Thinking that @cyrfer description was so detailed that maybe we could try some PR about it... What do you think guys?
@moacirosa Would be great if you're still willing to submit a PR :)
@moacirosa I got you.
@kaustavghosh06 I already submitted a simple fix in a PR but I've heard no feedback in 8 months.
https://github.com/aws/aws-sdk-js/pull/2797
Most helpful comment
I found the source of my problem. The code linked below attempts to add non-unique properties for
profileName
. My~/.aws/config
file contained entries called[default]
and[profile default]
, which causes the symptom.https://github.com/aws/aws-sdk-js/blob/master/lib/shared-ini/ini-loader.js#L10-L11
This code should take more care in case
~/.aws/config
is malformed. I don't know if I caused this with manual edits or using an old version ofaws configure
could have caused it.I removed one of my entries
[default]
and nowamplify init
works.