add method to get current accountId and region
See original GitHub issuecdk should provide a way to lookup the aws accountId and region that the cdk app is run under.
the current methods (e.g. cdk.Stack.find(this).accountId
or stack.region
) only return the values if they were set explicitly in the stack environment. otherwise they return tokens that won’t resolve until deploy. I can’t use these values in my cdk code to check if the account or region matches certain known combinations, which is something I need to do to vary a few details of my stack depending on where it gets deployed.
stack.requireRegion
and stack.requireAccountId
currently provide the desired behavior, but this conflicts with the api docs for these methods, which say that they will throw an Error if the values weren’t explicitly set in the environment.
A little more color on the scenario I’m working with… When I’m working on the cdk code I test in a transient account and would like cdk to create the entire stack. But when the stack is deployed in the real target account, there are some existing resources that need to be imported instead of created.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top GitHub Comments
The recommended way is:
Stack.of(this).account
andStack.of(this).region
. Closing for now. Feel free to reopen.Python:
self.account
andself.region
TypeScript:this.account
andthis.region