I am using a construct in my stack to create an EC2 instance. Inside the construct, I want to verify that the account number is valid before continuing. However, I am struggling to get the account number to test against. Any time I reference Stack.account whether printing it or setting it to a variable I get <property object at 0x0...> instead of an account number as a string. I am using CDK V2 and according to the CDK API Stack.account should return a string of the account the stack will be deployed to, but it is not. Is there a way I can get the account value returned as a string? Thanks.
Each section of code below comes from different files within my project.
Code that calls Stack Creation:
from temp_stack import TempStack
app = App()
windows_stack = TempStack(app,
"temp_stack",
stack_params = parameters,
env = {
'account': parameters['account'],
'region': 'us-east-1'
}
)
Stack Creation:
from constructs import Construct
from construct_library import Instance
class TempStack(Stack):
def __init__(self, scope: Construct, construct_id: str, stack_params: dict, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
hosts = stack_params['hosts']
#Instance is the construct creating the EC2
test_instance = Instance(self, host['hostname'], host, instance_sg=sec_group).instance
Within the Instance Construct:
from constructs import Construct
from aws_cdk import Stack
class Instance(Construct) :
print(Stack.account)
#Output is: <property object at 0x0...>
test = Stack.account
print(test)
#Output: <property object at 0x0...>