AWS CDK Python (No Credentials Found)

Question:

I am trying to using the command CDK Bootstrap after I have set up my virtual environment using the AWS CDK. This is the code for my application that the command above is pulling credentials from.

#!/usr/bin/env python3

from aws_cdk import core

from hello.hello_stack import MyStack


app = core.App()
MyStack(app, "hello-cdk-1", env={'account':'IDHERE','region': 'us-east-2'})
MyStack(app, "hello-cdk-2", env={'account':'IDHERE','region': 'us-west-2'})

app.synth()

Obviously I have taken the accountID out.
When using the command CDK Bootstrap here is my error output

 ❌  Environment aws://ACCOUNTIDHERE/us-west-2 failed bootstrapping: Error: Need to perform AWS calls for account ACCOUNTIDHERE, but no credentials found. Tried: default credentials.
    at CredentialsCache.getCredentials (/usr/local/lib/node_modules/aws-cdk/lib/api/util/sdk.ts:261:11)
    at CredentialsCache.get (/usr/local/lib/node_modules/aws-cdk/lib/api/util/sdk.ts:223:25)
    at SDK.cloudFormation (/usr/local/lib/node_modules/aws-cdk/lib/api/util/sdk.ts:117:20)
    at Object.deployStack (/usr/local/lib/node_modules/aws-cdk/lib/api/deploy-stack.ts:56:15)
    at Object.bootstrapEnvironment (/usr/local/lib/node_modules/aws-cdk/lib/api/bootstrap-environment.ts:93:10)
    at /usr/local/lib/node_modules/aws-cdk/bin/cdk.ts:270:24
    at async Promise.all (index 1)
Need to perform AWS calls for account ACCOUNTIDHERE, but no credentials found. Tried: default credentials.
Asked By: aroe

||

Answers:

Did you run aws configure at first?
Try to cat ~/.aws/credentials, if you see something like everything must be OK:

[default]
region = us-east-1
aws_access_key_id = *********************
aws_secret_access_key = ******************************************

Or you don’t have aws_access_key_id/aws_secret_access_key in [default] section.
All this information you can read here – https://cdkworkshop.com/15-prerequisites/200-account.html (official CDK Workshop).

Answered By: anton.uspehov

There was something installed on my root directory that was preventing my node module from executing the cdk. I reimaged my Mac and it worked. Thank you.

Answered By: aroe

Just try to use using the environment variables:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

It works for me.

I’m using cdk version 1.57.0

Answered By: Denis Liger

In my case I get temporary credentials using aws-runas and set it using code editor terminal(windows 10).

set AWS_ACCESS_KEY_ID=..........
set AWS_SECRET_ACCESS_KEY=.......
set AWS_SESSION_TOKEN=...........
set AWS_REGION=.......

With code editor terminal I got the same issue, but with a different window command prompt, I able to run bootstrap and deploy commands without any issue.

Answered By: Sudheera