Closed wormym1011 closed 1 year ago
Looks like the error comes from CfnOutput
but I am not very sure. Let's simplify the provided sample.
Are you able to run this?
from aws_cdk import (
Stack, CfnOutput,
aws_ec2 as ec2,
)
from constructs import Construct
class VpcStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
self.vpc = ec2.Vpc.from_lookup(self, 'Vpc', is_default=True)
@property
def get_vpc_id(self) -> str:
return self.vpc.vpc_id
class ConsumerStack(Stack):
def __init__(self, scope: Construct, construct_id: str, vpc_stack, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
CfnOutput(self, construct_id, value=str(vpc_stack.get_vpc_id))
On cdk deploy --all
you should see the vpcId in the output. It works for me. Are you able to deploy that?
Yes, it works like my code has been implemented as well
# str(vpc_stack.get_vpc_id) something likes <property object at 0x10d389e50>
CfnOutput(self, id, value=str(vpc_stack.get_vpc_id), export_name="tired")
same way with you
CfnOutput(self, construct_id, value=vpc_stack.get_vpc_id)
that returned
ConsumerStack | <property object at 0x1097f5a90>
But I need to inject the real data into some next steps likes real subnetid, real vpc_id, etc.. We can not input value <property object at 0x1097f5a90> into
subnet_ids=[
vpc_stack.get_etl_subnet_id_1a,
vpc_stack.get_etl_subnet_id_1b,
vpc_stack.get_etl_subnet_id_1c
],
transit_gateway_id=DX_TGW_ID,
vpc_id=vpc_stack.get_vpc_id,
Normally it should be worked as I have done many times before, the real value will be put while cdk deploy running.
If I remove str cast then error returned:
ConsumerStack(app, "**### ConsumerStack**", vpc_stack=DebugVpcStack, env=env_sing)
File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 112, in __call__
inst = super().__call__(*args, **kwargs)
File "/Users/wormym/cdp-cdk/edla_vpc/VpcConsumer.py", line 12, in __init__
CfnOutput(self, construct_id, value=vpc_stack.get_vpc_id)
File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 112, in __call__
inst = super().__call__(*args, **kwargs)
File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/aws_cdk/__init__.py", line 5755, in __init__
props = CfnOutputProps(
File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/aws_cdk/__init__.py", line 5918, in __init__
check_type(argname="argument value", value=value, expected_type=type_hints["value"])
File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/typeguard/__init__.py", line 785, in check_type
raise TypeError(
TypeError: type of argument value must be str; got property instead
Can you remove str() in Cfnoutput ? Normally, it should be output string as well with readable text likes: vpc-xxxxxxxxx. Not property likes
<property object at 0x1097f5a90>
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
@wormym1011 Could you solve this issue? I have the same but with event bridge schema target parameters.
Describe the bug
Code from app.py
Code from VPCStack.py
Code from VPCRoutingStack.py
Error return:
Expected Behavior
Actually I have many nested stack before from cdkv1 to v2 and migrated v1 to v2 as well. All working as expected till now. but this is new project and suddenly I faced this problem. From my point of view the @property already string, and it should be get the real value while runtime of cdk.
Current Behavior
It returned error
Traceback (most recent call last): File "app.py", line 13, in <module> VPCRoutingStack(app, "VPCRoutingStack", vpc_stack=VPCStack) File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 112, in __call__ inst = super().__call__(*args, **kwargs) File "/Users/wormym/cdp-cdk/edla_vpc/VPCRoutingStack.py", line 21, in __init__ CfnOutput(self, id, value=vpc_stack.get_vpc_id, export_name="cccc") File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/jsii/_runtime.py", line 112, in __call__ inst = super().__call__(*args, **kwargs) File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/aws_cdk/__init__.py", line 5755, in __init__ props = CfnOutputProps( File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/aws_cdk/__init__.py", line 5918, in __init__ check_type(argname="argument value", value=value, expected_type=type_hints["value"]) File "/Users/wormym/cdp-cdk/.venv/lib/python3.8/site-packages/typeguard/__init__.py", line 785, in check_type raise TypeError( TypeError: type of argument value must be str; got property instead
Reproduction Steps
init cdk with python language Create 3 files that I explained:
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.84
Framework Version
No response
Node.js Version
node 16/18
OS
os x / ubuntu
Language
Python
Language Version
3.8
Other information
requirements.txt: aws-cdk-lib==2.84.0 constructs==10.2.55 python-dotenv