dI created a custom resource through CDK and return a certain "CommaSeparatedString" as part of the response
return {
Status: "SUCCESS",
RequestId: event.RequestId,
StackId: event.StackId,
LogicalResourceId: event.LogicalResourceId,
PhysicalResourceId: event.ServiceToken,
Data: { CommaSeparatedString: "ABC,XYZ,TTT"},
};
I then access this in my CDK stack as below:
myCommaSeparatedString = myCustomResource.getAttString("CommaSeparatedString");
I want to convert this string into a list of strings, but doing this has no effect!
listOfString = myCommaSeparatedString.split(",");
I believe this is because at deployment time, the value of getAttString will be a placeholder in CDK (something like [ ‘${Token[TOKEN.97]}’ ] and hence doesn’t process the actual value.
Since the Data map in the CDK Custom resource response doesn’t support any other complex data types but only String this seems technically impossible.
Does anyone have any ideas or used CDK custom resources to return complex data types?
2
Answers
I am not sure if this would help, but the getAttString(attribute: string) accepts string
and your response returns data: {key: comma separated list}
may be if you destruct your response
Short answer:
Long answer:
The reason why your
split
function has no effect is becausemyCommaSeparatedString
value is not available at synthesize time.If instead of a dynamic value, you would have
myCommaSeparatedString = "ABC,XYZ,TTT"
instead, you won’t have that issue.Using Cloudformation Intrinsic function reference will handle those cases of dynamic value processing.
You could also validate CDK behavior by doing
cdk synth
before doing acdk deploy
.Before:
cdk synth
After:
cdk synth