cloudtools / troposphere

troposphere - Python library to create AWS CloudFormation descriptions
BSD 2-Clause "Simplified" License
4.93k stars 1.45k forks source link

Lines in AWS CodeBuild buildspec commands are being broken when converted to YAML #2061

Closed eamonnfaherty closed 1 year ago

eamonnfaherty commented 2 years ago

When you create an AWS Codebuild project with a buildspec and have lines longer than 200 chars the resultant YAML generated by troposphere is not accepted by CodeBuild as a valid buildspec as the lines are broken onto multiple lines.

This is the default behaviour in pyyaml. To resolve you need to specify a width parameter to dump to avoid this from happening.

markpeek commented 2 years ago

troposphere uses cfn_flip to convert from json to yaml and cfn_flip then calls pyyaml. Introducing a width parameter would require changes to both packages. An easy workaround is to emit the yaml via something like this:

...
buildspec = """long line"""
t = Template()
t.add_resource(Source(BuildSpec=buildspec, Type="NO_SOURCE"))
print(yaml.dump(t.to_dict(), width=10000))