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
gefragt vor 2 Jahren1513 Aufrufe
1 Antwort
0
Akzeptierte Antwort

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
SUPPORT-TECHNIKER
Wayne_G
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen