Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws cdk to use non-default profile

Tags:

I don't want to use my default aws profile and account for cdk development

So I created a new account and a new profile cdkprof using aws configure --profile cdkprof .

I have verified in ~/.aws/credentials and ~/.aws/config files that the new profile created correctly. running export AWS_PROFILE=cdkprof && aws configure list && aws sts get-caller-identity returns me my profile details correctly.

I have also exported

  • CDK_DEFAULT_REGION,
  • CDK_DEFAULT_ACCOUNT,
  • AWS_DEFAULT_REGION,
  • AWS_PROFILE,
  • AWS_SECRET_ACCESS_KEY and
  • AWS_ACCESS_KEY_ID

and these are available as environment variables in bash.

However when I try to run :

$ npx cdk bootstrap --profile cdkprof   

I get the error

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

How do I use my new profile and account with the cdk commands?

Thanks.

like image 278
bearrider Avatar asked Feb 13 '21 13:02

bearrider


People also ask

What is bootstrapping in CDK?

Bootstrapping is the process of provisioning resources for the AWS CDK before you can deploy AWS CDK apps into an AWS environment. (An AWS environment is a combination of an AWS account and Region).

Does CDK deploy to CloudFormation?

The AWS CDK Toolkit, the CLI command cdk , is the primary tool for interacting with your AWS CDK app. It executes your app, interrogates the application model you defined, and produces and deploys the AWS CloudFormation templates generated by the AWS CDK.


1 Answers

By default, CDK commands will use the default AWS CLI profile. However, you can specify a named profile for a project by adding it to the file which handles CDK commands. For a TypeScript project, this is done in cdk.json at the project root:

{
  "app": "npx ts-node --prefer-ts-exts bin/project.ts",
  "profile": "cdkprof",
  "context": {
    ...
  }
}

Then, your named profile will be used when you run commands such as cdk bootstrap.

like image 128
Alex Avatar answered Nov 25 '22 03:11

Alex