1

Is there a possible way to obtain the value from a cdk command. Say, if there are two profiles namely foo, boo and during syth I would mention them as

cdk synth --profile foo

and later in the code there is a need to change a property as foo (i:e: the profile name).

While performing the synth with the profile boo again I need to change the property in the code. So, is there any possible way to obtain the profile value from the cdk command rather than changing the code each time.

Krithick S
  • 408
  • 3
  • 15

1 Answers1

1

Since profile names are very arbitrary (anyone can set them up differently), the results would depend on who runs the cdk synth. This is obviously not good practice.

If you want to provide a certain value based on what account you are deploying to, I suggest you use the cdk.context.json file, or pass it inline `cdk synth --profile foo --context profile=foo. Then in your code:

const myProfile = this.node.tryGetContext('profile');

I know it's kinda double but it's decouples to logic from you local profile naming convention.

LRutten
  • 1,634
  • 7
  • 17
  • 1
    Though it wasn't a good practice, it worked out great in my case. Adding to this to send another parameter can be done by `cdk synth --profile foo --context param=value --context param=value` – Krithick S Sep 07 '21 at 10:39