cdk deploy / destroy seem to ignore profile

0

I have two AWS profiles, let's say default and another. I have CDK Typescript application where env is defined such:

env: { 
    account: process.env.CDK_DEFAULT_ACCOUNT, 
    region: process.env.CDK_DEFAULT_REGION 
  }

Now, I am trying to deploy it to my another profile.

npx cdk deploy --profile another

I get the stack deployed to my primary profile. I get stack ARN arn:aws:cloudformation:us-west-2:123123123123:stack/CdkTutorialStack/79093390-6c37-11ec-8f4f-023fb3d3a5bd where 123123 is my account on the primary profile. Interesting, npx cdk diff work as expected - shows diff from correct account

If I hardcode account in the code, and specify --profile another, CDK deploys to correct destination (which makes sense, it takes credentials from the profile). But is there a way to not hardcode the account, and still deploy to the account specified in the profile.

profile picture
virshu
已提问 2 年前1512 查看次数
1 回答
0
已接受的回答

There does appear to be a difference in behavior between the AWS CLI and CDK when it comes to handling of the config and credentials files. I found a GitHub issue on the aws-cdk project that describes the same issue you seem to be facing here (1)

Some are reporting success by adding a source_profile to their ~/.aws/credentials file. Despite having the same name, it appears that CDK may not be looking at non-default credentials when supplied with a --profile

You may also find more details on the overall behavior of CDK by adding the --verbose flag in your CDK commands

(1) https://github.com/aws/aws-cdk/issues/5053#issuecomment-770527518

AWS
支持工程师
Wayne_G
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则