Skip to content

Magic String in ec2.LinuxOS.createUserData() #2674

@KingOfPoptart

Description

@KingOfPoptart

Describe the bug
There's no way to have complete control over your generic Linux's userdata, #!/bin/bash gets injected as the first line. There are scenarios where a user would want #cloud-boothook as the first line instead for example, or to specify a different shell

To Reproduce

this._asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
        minCapacity: 1,
        maxCapacity: 1,
        vpc: vpc.Vpc,
        vpcSubnets: {
            subnetType: ec2.SubnetType.Public
        },
        instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.Burstable2, ec2.InstanceSize.Micro),
        machineImage: new ec2.GenericLinuxImage({
            'us-west-2': 'ami-xxxx',
        })
    },
    elbProps : {
        ...
    });
const userData = "#cloud-boothook\n#!/bin/bash\nsudo echo hello";
this._asg.addUserData(userData);

Creates this CFN:

ASGLaunchConfigC00AF12B:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: ami-xxxxxxx
      InstanceType: t2.micro
      UserData:
        Fn::Base64: |-
          #!/bin/bash
          #cloud-boothook
          #!/bin/bash
          echo hello

Expected behavior
I would have expected my CFN to look like

      UserData:
        Fn::Base64: |-
          #cloud-boothook
          #!/bin/bash
          echo hello

or to at least have a parameter I can set to omit #!/bin/bash, or somewhere I can setUserData() instead of addUserData()

Version:

  • OS: OSX
  • Programming Language: TypeScript
  • CDK Version: 0.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions