[core] know from within the script which action is executed #9619
Labels
@aws-cdk/core
Related to core CDK functionality
feature-request
A feature should be added or improved.
needs-triage
This issue or PR still needs to be triaged.
I would like to know inside my CDK script which action is being executed on it - be it synth, deploy, destroy etc.
Use Case
Reusable stacks
Defining reusable stacks and resources requires to provide differences as context variables. E.g. using a service name in a resource name is possible when having it defined as (in my case Python):
name=f"{self.node.try_get_context('service')}-example-resource"
Then I can successfully deploy different instances by specifying the variable on the command line as context:
cdk deploy my-reusable-stack --context service="my-service-A"
However, now I also need to specify the context variable even for every synth to not get an error. From within the script, for that case I'd like to check if this is a synth action and set the service variable to a dummy value.
Context sensitive actions
For example, I'd like to execute additional actions if my "stage" context variable is "prod", but only if the action is "deploy" or "destroy", e.g. update an asset inventory that does not include non-prod resources or any other action dependent on a combination of those contexts.
Proposed Solution
Something like a "get_cdk_action" function, to be used like this for the use cases mentioned above:
Other
I realize those could be achieved by wrapper scripts but I really don't see why I should do that and have to take care of handling exit codes and outputs of the external cdk command if I can do basically everything in app.py already - just limited by not knowing the full execution context.
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: