skip to Main Content

I keep getting yaml validation errors for a part of my yaml that is not inteded to be yaml, but linux bash script,

(I’m trying to create a CloudFront template to start an EC2 isntance on AWS)

the error message is:

All mapping items must start at the same column at line 14, column 1

and it refers to the -y after yum update

Resources:
  MyInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-051f8a213df8bc089 
      InstanceType: t2.micro
      KeyName: mydockertestKP
      SecurityGroupIds:
        - sg-12345678 
      UserData:
        Fn::Base64:
          Fn::Sub |
            #!/bin/bash
            yum update -y
            yum install -y docker

            systemctl start docker

            curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
            chmod +x /usr/local/bin/docker-compose

anyone knows what can I do to make the aws yaml validator to not treat the bash script as yaml ?

(VS2022 and yamllint.com show the same error)

2

Answers


  1. Chosen as BEST ANSWER

    Looks like I needed to add a : after the Fn::Sub


  2. The below should fix the issue.

    Resources:
      MyInstance:
        Type: AWS::EC2::Instance
        Properties:
          ImageId: ami-051f8a213df8bc089
          InstanceType: t2.micro
          KeyName: mydockertestKP
          SecurityGroupIds:
            - sg-12345678
          UserData:
            Fn::Base64:
              Fn::Sub: "#!/bin/bash yum update -y yum install -y docker systemctl start docker
                curl -L
                https://github.com/docker/compose/releases/latest/download/docker-c
                ompose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
                chmod +x /usr/local/bin/docker-compose"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search