question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add method to get current accountId and region

See original GitHub issue

cdk 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

86reactions
eladbcommented, Jul 21, 2019

The recommended way is: Stack.of(this).account and Stack.of(this).region. Closing for now. Feel free to reopen.

43reactions
brianfoodycommented, Jul 6, 2020

Python: self.account and self.region TypeScript: this.account and this.region

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get Account ID and Region in AWS CDK | bobbyhadz
The recommended way by the CDK team to get access to the accountId and region properties is to use the Stack.of(this).account and Stack.of(this).region...
Read more >
How to get the account id with cdk - typescript - Stack Overflow
One way to get the value you need would be to add this to your stack constructor: // Publish the custom resource output...
Read more >
Pseudo parameters reference - AWS CloudFormation
Lists the details of the available pseudo parameters that are predefined by AWS CloudFormation.
Read more >
How to get the AWS Account ID in Lambda Python
I thought it was easy as getting the AWS Region but it was not. Luckily there is a way to get it, use...
Read more >
Account Identifiers - Snowflake Documentation
Non-VPS Account Locator Formats by Cloud Platform and Region ... takes one of the following forms, depending on where and how the identifier...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found