to_yaml fails for StepFunctions StateMachine with inline DefinitionString
iasoon opened this issue · 4 comments
Example to reproduce, tested with cfn-flip==1.2.3:
import cfn_flip
json_stm = r"""
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"An example template for a Step Functions state machine.",
"Resources":{
"MyStateMachine":{
"Type":"AWS::StepFunctions::StateMachine",
"Properties":{
"StateMachineName":"HelloWorld-StateMachine",
"StateMachineType":"STANDARD",
"DefinitionString":"{\"StartAt\": \"HelloWorld\",
\"States\": {\"HelloWorld\": {\"Type\": \"Task\", \"Resource\":
\"arn:aws:lambda:us-east-1:111122223333;:function:HelloFunction\", \"End\": true}}}",
"RoleArn":"arn:aws:iam::111122223333:role/service-role/StatesExecutionRole-us-east-1;"
}
}
}
}
"""
cfn_flip.to_yaml(json_stm)
Result:
Traceback (most recent call last):
File "test.py", line 23, in <module>
cfn_flip.to_yaml(json_stm)
File "/home/iasoon/.local/lib/python3.9/site-packages/cfn_flip/__init__.py", line 74, in to_yaml
data = cfn_literal_parser(data)
File "/home/iasoon/.local/lib/python3.9/site-packages/cfn_clean/__init__.py", line 163, in cfn_literal_parser
source[key] = cfn_literal_parser(value)
File "/home/iasoon/.local/lib/python3.9/site-packages/cfn_clean/__init__.py", line 163, in cfn_literal_parser
source[key] = cfn_literal_parser(value)
File "/home/iasoon/.local/lib/python3.9/site-packages/cfn_clean/__init__.py", line 155, in cfn_literal_parser
if not has_intrinsic_functions(source["Properties"][item[1]].keys()):
AttributeError: 'str' object has no attribute 'keys'
The example json was taken from https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-definitionstring .
This issue arises when constructing a template with (troposphere)[https://github.com/cloudtools/troposphere], and dumping it to yaml.
The example does work when using flip
instead of to_yaml
, since the code paths are different and flip
does not use cfn_literal_parser
. Is there a reason for this?
I'd be happy to contribute a fix if we can clear this up.
Thanks for sharing this issue.
I'm investigating the bug and will get back to you soon.
Hi Iasson,
I found the issue and I will submit a PR with the fix.