mcy
mcy

Reputation: 89

ERROR: Unable to resolve AWS account to use. It must be either configured when you define your CDK or through the environment

I'm learning how to use aws cdk, here is my code, I wanna do "cdk deploy --profile myProfile", got "Unable to resolve AWS account to use. It must be either configured when you define your CDK or through the environment",

but I already specifying my Credentials and Region by using, can anyone help me with that.

cdk doctor
ℹ️ CDK Version: 1.30.0 (build 4f54ff7)
ℹ️ AWS environment variables:
  - AWS_PROFILE = myProfile
  - AWS_SDK_LOAD_CONFIG = 1
ℹ️ CDK environment variables:
  - CDK_DEPLOY_ACCOUNT = 096938481488
  - CDK_DEPLOY_REGION = us-west-2
aws configure --profile myProfile

AWS Access Key ID [****************6LNQ]:
AWS Secret Access Key [****************d9iz]:
Default region name [us-west-2]:
Default output format [None]:
import core = require('@aws-cdk/core');
import dynamodb = require('@aws-cdk/aws-dynamodb')
import { AttributeType } from '@aws-cdk/aws-dynamodb';
import { App, Construct, Stack } from "@aws-cdk/core";

export class HelloCdkStack extends core.Stack {
  constructor(scope: core.App, id: string, props?: core.StackProps) {
    super(scope, id, props);

    new dynamodb.Table(this, 'MyFirstTable', {
          tableName: 'myTable1',
          partitionKey: {
                name: 'MyPartitionkey',
                type: AttributeType.NUMBER
              }
        });
  }
}

const app = new App();
new HelloCdkStack(app, 'first-stack-us', { env: { account: '***', region: 'us-west-2' }});

app.synth();

Upvotes: 3

Views: 8153

Answers (1)

mon
mon

Reputation: 22244

It should be the bug as in [master] CDK CLI Authentication Issues #1656.

if you have ~/.aws/credentials and ~/.aws/config they both can't have a default profile section.

removing [profile default] from ~/.aws/config solved the issue! I had both [default] and [profile default]. Please see #1656

resolved the issue insert the AWS keys in the "config" file inside ~/.aws folder, and not inside "credentials" file

Upvotes: 5

Related Questions