Long strings/refs incorrectly split over newlines causing broken user-data/etc
See original GitHub issueWhen I am building strings to use in my user-data/etc, CDK seems to incorrectly insert newlines (at long lines?), causing scripts to break.
Relevant Snippets from code:
const cfnInitCmd = `/opt/aws/bin/cfn-init -v --stack=${new cdk.AwsStackName} --region=${new cdk.AwsRegion} --resource=${asgLaunchConfig.logicalId}`;
appAsg.addUserData(
"yum install -y aws-cfn-bootstrap;",
`${cfnInitCmd} --configsets install;`,
`/opt/aws/bin/cfn-signal --stack=${new cdk.AwsStackName} --region=${new cdk.AwsRegion} --resource=${asgLaunchConfig.logicalId} --exit-code \$?;`,
);
When synthesized, this ends up like:
AppAutoScalingGroupLaunchConfig48178128:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
..snip..
UserData:
Fn::Base64:
Fn::Join:
- ""
- - |-
#!/bin/bash
yum install -y aws-cfn-bootstrap;
/opt/aws/bin/cfn-init -v --stack=
- Ref: AWS::StackName
- " --region="
- Ref: AWS::Region
- >-2
--resource=AppAutoScalingGroupLaunchConfig48178128 --configsets
install;
/opt/aws/bin/cfn-signal --stack=
- Ref: AWS::StackName
- " --region="
- Ref: AWS::Region
- " --resource=AppAutoScalingGroupLaunchConfig48178128 --exit-code
$?;"
Which ends up in the end user-data as:
#!/bin/bash
yum install -y aws-cfn-bootstrap;
/opt/aws/bin/cfn-init -v --stack=TokenizedEC2 --region=ap-southeast-2 --resource=AppAutoScalingGroupLaunchConfig48178128 --configsets
install; /opt/aws/bin/cfn-signal --stack=TokenizedEC2 --region=ap-southeast-2 --resource=AppAutoScalingGroupLaunchConfig48178128 --exit-code $?;
Note how the install
parameter ends up on a new line, when it shouldn’t, which then breaks things.
This is also happening in my AWS::CloudFormation::Init
Metadata
override, breaking my /etc/cfn/cfn-hup.conf
config.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Easiest way to split a string on newlines in .NET?
The safest bet, is to first do a string replace for all "\r\n" and then split on "\n". Where using .Newline fails, is...
Read more >Handle line breaks (newlines) in Python - nkmk note
This article describes how to handle strings including line breaks (line feeds, new lines) in Python. Create a string containing line breaks.
Read more >Line breaks in text fields - A Beginner's Guide to Clean Data
When a parser hits a line break and does not recognize it as part of a string field, it will assume that it...
Read more >Split strings at newline characters - MATLAB splitlines
This MATLAB function splits str at newline characters and returns the result as the output array newStr.
Read more >When a Line Doesn't Break
We expect a line to break when the text on that line reaches the parent box boundaries. We see this every time we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This should be fixed by the just-released version 1.1.0 of
yaml
. It’s also now clearer how to disable line folding altogether.If we allow users to synthesize YAML, then it should work. It would be an awful experience if “cdk deploy” worked and “cdk synth” didn’t. Happy to continue to try make YAML work, but I am concerned…