aws-cdk/core: Tokenization.reverseCompleteString() Error updates / erroneous behavior in Stack.exportValue() #31035
Labels
@aws-cdk/core
Related to core CDK functionality
bug
This issue is a bug.
p3
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Describe the bug
Hey team, was deep diving the exportValue() function because of an error that it was throwing when trying to export route 53 properties / IDs.
The error throwing from Tokenization.reverseCompleteString() is the concatenation error. For clarity I think this error needs to be changed to include the possibility of this getting called from Stack.exportValue().
Expected Behavior
The error checking should be aware that exportValue could call for a token from a source that returns a token list, like route53, potentially being able to identify when a fragment list is due to a multi return from reverseString(), or an actual concatenation.
Basically the error currently, doesn't fit this particular situation, where the user is not in fact concatenating anything.
Current Behavior
Here is what I'm thinking; it seems like the purpose of the concatenation error is in case someone is calling one of these tokenization methods directly, and when parsing the token fragments from reverseString() it's assuming if you ended up with a list of fragments then you must of somehow gotten more than one value back from the splitstring, therefore some kind of concat happened. I think this is a side effect in this case of route53 using intrinsic sting lists. This summarizes pretty well https://docs.aws.amazon.com/cdk/v2/guide/tokens.html#tokens_list
So when calling reverseCompleteString(), route53 is simply returning a list of fragments due to it's natural behavior, but this isn't a user error. The error that you should not pass in a concatenation in this case makes no sense to the user since that's not what they did (see below code block), rather the return behavior for this particular cfn construct is causing the issue on it's own.
Reproduction Steps
create a hosted zone using CDK, then the following:
Possible Solution
You can solve this simply by adding a "name" to the exportValue() function when called. Which brings up an interesting point. What is the purpose of using exportValue() without a name? it seems like a risk to have the build parse the CFN data just to add a name to the exported value. Potentially a simple fix would be to just remove this side of exportValue() all together and force the user to include a name when using this function.
Additionally it seems like in Tokenization.reverse() the option options.failConcat could maybe help with this situation, but Stack.exportValue() doesn't include this as part of the inputs, so there wouldn't be a way for a user to override in this fashion either.
Additional Information/Context
Overall seems like these functions just aren't fully meshing, it's hard to say what the best fix / root cause is, since it could very well be route53 in the end too.
CDK CLI Version
2.149.0
Framework Version
No response
Node.js Version
v18.20.2
OS
Mac Sonoma 14.5
Language
TypeScript
Language Version
^5.0.4
Other information
No response
The text was updated successfully, but these errors were encountered: