(Route53): HostedZone name_servers cannot be an automatic export with self.export_value
#32420
Labels
@aws-cdk/aws-route53
Related to Amazon Route 53
bug
This issue is a bug.
needs-triage
This issue or PR still needs to be triaged.
Describe the bug
If you have two stacks, and want to pass name servers from stack A to stack B, CDK will create the automatic import/export to help. There's no way to set
self.export_value
on the hosted zone's nameservers export, to keep it declared when re-deploying. (This also blocks removing automatic cross stack references)Regression Issue
Last Known Working CDK Version
No response
Expected Behavior
If you add
self.export_value(hosted_zone.hosted_zone_name_servers)
on a export that already exists, it becomes apart of the stack and you can deploy again.Current Behavior
The main error is it sees the nameserver as a list, which it is. It must be a string:
Template format error: Every Value member must be a string.
I found a way to change it to the string it's expecting in the next section, but since I transformed the object, it no longer can reference the same object/export.
Reproduction Steps
With the following App:
And inside
./example_stacks/example_stacks.py
:The
self.imported_hosted_zone
is a domain bought from AWS, so that hosted zone doesn't live in any stack.Deploy both stacks to your account:
Then comment out ExampleStackB inside
app.py
, and deploy A again. (cdk deploy ExampleStackA
). You'll get(Commenting out B because in the normal architecture, I have a one-to-many with one A, and many B's. Sometimes I need to only deploy A too, it's shared resources for everything. BUT more basically, if both stacks in different apps, that'd also hit this).
The normal way to fix this issue, is to add
self.export_value(resource)
to the end of stack A. When I try to do that with the hosted_zone_name_servers (withself.export_value(self.hosted_zone.hosted_zone_name_servers)
):self.export_value(self.hosted_zone.hosted_zone_name_servers)
to the end of stack Acdk deploy ExampleStackB
)You'll get an error
Template format error: Every Value member must be a string.
. It's a list of one item.You can change it away from a list with
self.export_value(Fn.join("||", self.hosted_zone.hosted_zone_name_servers))
, but then it doesn't recognize it as the same export as before. You'll get:Even if you set the name and somehow match it to the generated one, it'll complain about duplicates and fail.
And if you import the
self.hosted_zone
itself from A to B withroute53.PublicHostedZone.from_hosted_zone_attributes
, thenzone.hosted_zone_name_servers
isNone
(which is expected, the docs say so).The only solution I've found so far, is to manually export/import it. This avoids CDK creating the automatic one that's blocking the stack_a deployments:
Possible Solution
Ideally to make
self.export_value(nameserver)
work like all the other objects I can callself.export_value
on.Additional Information/Context
No response
CDK CLI Version
2.171.1 (build a95560c)
Framework Version
No response
Node.js Version
v22.11.0
OS
Fedora 41
Language
Python
Language Version
Python 3.13.0
Other information
No response
The text was updated successfully, but these errors were encountered: