aws-cdk: CDK errors with no credentials have been configured if credentials file does not exist
when running cdk deploy, if a file does not exist at ~/.aws/credentials, cdk will exit with the message Need to perform AWS calls for account 1234, but no credentials have been configured..
There are many ways to provide aws credentials that don’t require the credentials file, so this should probably be fixed.
In the meantime, the fix is to simply create a file at the expected path (~/.aws/credentials)
Reproduction Steps
mv ~/.aws/credentials ~/.aws/credentials_backup
cdk deploy --verbose
Error Log
see above
Environment
- CLI Version : 1.30.0 (build 4f54ff7)
- Framework Version:
- OS :
- Language :
Other
This is 🐛 Bug Report
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 34
- Comments: 31 (4 by maintainers)
The file already exists for me with proper credentials, still not able to solve it. Anyone else facing the same issue?
I got around this by adding
--profile <profile-name>at the end of my cdk command with the profile name being the name in the~/.aws/credentialsfile .Contents of
~/.aws/credentials[aws-profile-name]aws_access_key_id=XXXaws_secret_access_key=XXXThen my CLI CDK commands will be:
cdk <cdk-command> --<cdk-options> --profile aws-profile-name@trondhindenes @DioNNiS - have you checked out this blog post which gets into how to use the
cdk-credentialplugin. It’s a tool I’d recommend when working with cross-account actions.I’ve found a fair amount of users who run into this message would have been saved a fair amount of grief if the plugin were used.
can you give it a go and let me know how it goes?
This issue is also coming from
Setting "CDK_DEFAULT_REGION" environment variable to us-east-1 Resolving default credentials Unable to determine the default AWS account: TypeError: Cannot redefine property: saml at Function.defineProperty (<anonymous>) at /usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:11:14 at Array.forEach (<anonymous>) at IniLoader.parseFile (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:8:26) at IniLoader.loadFrom (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:56:30) at Object.getProfilesFromSharedConfig (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/util.js:969:42) at ProcessCredentials.load (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials/process_credentials.js:75:31) at ProcessCredentials.coalesceRefresh (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials.js:205:12) at ProcessCredentials.refresh (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials/process_credentials.js:163:10) at ProcessCredentials.get (/usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials.js:122:12)How to check if it’s due to profile name conflicts
When can it happen when you have same entry in
~/.aws/configwith profile likeOr
Notice
profile samlandsamlThere’s this code in /usr/local/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js
It tries to define the saml property again and that’s where it fails
How to resolve?
Remove the entry with
[profile <some-name>]The trick for cdk to pick the right profile is to have
~/.aws/configfile well configured, this is how I’m doing it asAny other profile apart from
defaultshould be mentioned withprofilekeyword followed by the profile name, for instance,[profile sandbox], then other details in next line.using the environment variables:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_DEFAULT_REGIONworks for me.https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
cdk version
1.57.0I ran into this today as well.
Command cdk bootstrap aws://my-account-id/my-region
Error Environment aws://my-account-id/my-region failed bootstrapping: Error: Need to perform AWS calls for account my-account-id, but no credentials have been configured
I don’t have a credential file and, as per my understanding, I should not need one if I am following the best practice of using a dedicated administrative account with temporary credentials enabled.
My config looks like:
I tried adding an empty credential file but did not fix.
cdk ls -v
Removing the default profile
Why is this closed?
@shivlaks this bug (which I understand is fixed now) simply meant that a file had to exist on the filesystem for CDK to be able to work. I don’t have any issues with authentication or credentials, I just found that this file needed to exist (empty or not).
Sidenote: I had a look at the credential-plugin now. As sweet as it looks, one of CDK’s selling points is its cross-language support. This means that utilities and helpers also need to be cross-language. We’re standardized on python for all our “iac” stuff and so this plugin wouldn’t solve my issue since it seems to require a TS/JS-based cdk codebase.
What worked for me was running it with verbose option and found that one of the profiles was duplicated in config file
cdk ls -vSetting "CDK_DEFAULT_REGION" environment variable to us-east-1 Resolving default credentials Unable to determine the default AWS account: TypeError: Cannot redefine property: my-profile-nameat Function.defineProperty (<anonymous>) at /home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:11:14 at Array.forEach (<anonymous>) at IniLoader.parseFile (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:8:26) at IniLoader.loadFrom (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/shared-ini/ini-loader.js:56:30) at Object.getProfilesFromSharedConfig (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/util.js:969:42) at ProcessCredentials.load (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials/process_credentials.js:75:31) at ProcessCredentials.coalesceRefresh (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials.js:205:12) at ProcessCredentials.refresh (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials/process_credentials.js:163:10) at ProcessCredentials.get (/home/dmoreno/.nvm/versions/node/v16.3.0/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/credentials.js:122:12) ...After losing a couple of hours having authentication issues with named profiles, @ajaysuwalka solution helped me. Thanks so much!
by doing
cdk diff --profile "profile someName"instead ofcdk diff --profile someNameit worked.By the way, I’m using the version 1.58 of the CDK.
Oh wow. Two years later and this is still not resolved 😐
You can test your credential with this command :
My system time was wrong, I update my system time and it was good.
Ran into this today, moving the accounts_partitions.json in the cdk cache worked.
Not sure if this should be a new issue, but it’s certainly related. In my cases there are existing (non-empty) .aws/credentials and .aws/config files. But my deploy script defined AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID and AWS_DEFAULT_REGION. Despite the fact that per the docs those should be checked first, i was getting the same error.
My workaround was setting AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE to point to new, empty files
Issue still exists in latest CLI:
In my case, I attempted to bootstrap using a profile with an IAM role without a
~/.aws/credentialsfile:Creating the
credentialsfile for the IAM users resolved the issue.~/.aws/configwas the problemcdk diff -v --profile xyz, that verbosity switch-vwas the key, it exposed the issue.~/.aws/credentialsfile, all was in order there~/.aws/configI had a typo related to mysandboxprofile, unrelated to thexyzprofile.I get this issue on and off seemingly at random I’ll re set the environment variables, delete and create the creds and config files with some data, then delete again and eventually it works