27

I'm trying to deploy my stack to aws using cdk deploy my-stack. When doing it in my terminal window it works perfectly, but when im doing it in my pipeline i get this error: Need to perform AWS calls for account xxx, but no credentials have been configured. I have run aws configure and inserted the correct keys for the IAM user im using.

So again, it only works when im doing manually in the terimal but not when the pipeline is doing it. Anyone got a clue to why I get this error?

gospecomid12
  • 712
  • 3
  • 11
  • 25

10 Answers10

11

I encountered the same error message on my Mac. I had ~/.aws/config and credentials files set up. My credentials file had a user that didn't exist in IAM. For me, the solution was to go back into IAM in the AWS Console; create a new dev-admin user and add AdministratorAccess privileges like this .. enter image description here Then update my ~/.aws/credentials file with the new [dev-admin] user and added the keys which are available under the "Security Credentials" tab on the Summary page shown above. The credentials entry looks like this..

[dev-admin]
aws_access_key_id=<your access key here>
aws_secret_access_key=<your secret access key here>

I then went back into my project root folder and ran

cdk deploy --profile dev-admin -v

Not sure if this is the 'correct' approach but it worked for me.

SlackGadget
  • 487
  • 6
  • 9
8

If you are using a named profile other than 'default', you might want to pass the name of the profile with the --profile flag.

For example:

cdk deploy --all --profile mynamedprofile

If you are deploying a stack or a stage you can explicitly specify the environment you are deploying resources in. This is important for cdk-pipelines because the AWS Account where the Pipeline construct is created can be different from where the resources get dployed. For example (C#):

Env = new Amazon.CDK.Environment()
{
    Account = "123456789",
    Region = "us-east-1"
}

See the docs

nsquires
  • 899
  • 2
  • 8
  • 20
  • 1
    Ok, right now im using env to pass my account and region to different stacks, like you show! But it doesnt work anyways in pipeline, but only manually.. I'm getting a little bit frustrated :P – gospecomid12 Jun 23 '21 at 07:17
2

If you get this error you might need to bootstrap the account in question. And if you have a tools/ops account you need to trust this from the "deployment" accounts.

Here is an example with dev, prod and tools:

cdk bootstrap <tools-account-no>/<region> --profile=tools;
cdk bootstrap <dev-account-no>/<region> --profile=dev;
cdk bootstrap <prod-account-no>/<region> --profile=prod;

cdk bootstrap --trust <tools-account-no> --profile=dev --cloudformation-execution-policies 'arn:aws:iam::aws:policy/    AdministratorAccess';
cdk bootstrap --trust <tools-account-no> --profile=prod --cloudformation-execution-policies 'arn:aws:iam::aws:policy/   AdministratorAccess';
cdk bootstrap --trust <tools-account-no> --profile=tools --cloudformation-execution-policies 'arn:aws:iam::aws:policy/  AdministratorAccess';

Note that you need to commit the changes to cdk.context.json

Stian
  • 1,221
  • 1
  • 19
  • 26
1

The only way worked with me is to make sure that ~/.aws/config and ~/.aws/credentials files they both can't have a default profile section. So if you removed the default profile from both files, it should work fine with you :)

Here is a sample of my ~/.aws/config ====> (Note: i don't use default profile at all)

[profile myProfile]
sso_start_url = https://hostname/start#/
sso_region = REPLACE_ME_WITH_YOURS
sso_account_id = REPLACE_ME_WITH_YOURS
sso_role_name = REPLACE_ME_WITH_YOURS
region = REPLACE_ME_WITH_YOURS
output = yaml

And this is ~/.aws/credentials ====> (Note: i don't use default profile at all)

[myProfile]
aws_access_key_id=REPLACE_ME_WITH_YOURS
aws_secret_access_key=REPLACE_ME_WITH_YOURS
aws_session_token=REPLACE_ME_WITH_YOURS
source_profile=myProfile

Note: if it still doesn't work, so try to use one profile only in config and credentials holding your AWS configurations and credentials.

mibrahim.iti
  • 1,928
  • 5
  • 22
  • 50
1

I'm also new to this. I was adding sudo before cdk bootstrap command. Removing sudo made it work.

You can also do aws configure list to list down all the profiles to check if credentials are being created and stored in a proper manner.

GrozaFry
  • 41
  • 7
  • Yep was doing the same, the hint for me was the verbose output specified that it was looking for credentials in `root/.aws/credentials` – Dan Gardner Nov 07 '22 at 10:56
1

Sometimes this error comes when you system time is incorrect. Mine was just off by 2 minutes and this was the error that it gave. Try using the AWS Toolkit extension to get the correct error. Just changing the local system time was enough for me.

Azrael
  • 21
  • 1
0

If using a CI tool, check the output of cdk <command> --verbose for hints at the root cause for credentials not found.

In one case, the issue was simply the ~/.aws/credentials file was missing (although not technically required if running on EC2) - more details in this answer.

Efren
  • 4,003
  • 4
  • 33
  • 75
0

I too had this issue. when I checked ~/.aws/credentials, it was having some older account details. So I just deleted that file. and

==> aws configure

==> cdk bootstrap aws://XXXXXX/ap-south-1

it worked.

Raghu Vallikkat
  • 365
  • 5
  • 16
0

For working with SSO accounts and the (new) IAM Identity Center, make sure you have the latest aws-cdk installed.

npm install -g aws-cdk

Then run your command

cdk deploy <stackname> [--profile name]

Pay special attention to the version of your CDK in packages.json. If you are running npx cdk deploy you are using your packages.json cdk version, so you'll have to update it!

In my case, I was using aws-cdk@2.28.0 which did not support SSO credentials. Upgrading to aws-cdk@2.69.0 solved the problem.

dzlatkov
  • 646
  • 6
  • 7
0

Was facing the similar issue with CDK deploy|diff|bootstrap —profile my-profile

Strangely it worked for me by doing these two steps:

  1. export NODE_TLS_REJECT_UNAUTHORIZED=0 (Check if the issue is resolved after this, I know its insecure method but i was stuck with this issue for long)

  2. If you have same profile info in .aws/credentials and .aws/config file both, so just move profile related all configuration under one file ~ credentials