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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠