question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Long strings/refs incorrectly split over newlines causing broken user-data/etc

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
eemelicommented, Dec 11, 2018

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.

1reaction
eladbcommented, Dec 10, 2018

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found