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 年前檢視次數 1513 次
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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南