2

I'm writing the cloudformation template that includes ec2 instance. In userdata block, I want to create a file with some content. In the file, I'm initializing local variable MY_MESSAGE, but next, after the template is deployed this variable is not shown in the file.

original temlate:

EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-03368e982f317ae48
      InstanceType: t2.micro
      KeyName: ec2
      UserData:
        !Base64 |
        #!/bin/bash
        cat <<EOF > /etc/aws-kinesis/start.sh
        #!/bin/sh
        MY_MESSAGE="Hello World"
        echo $MY_MESSAGE

output file in ec2 instance:

#!/bin/sh
MY_MESSAGE="Hello World"
echo 

As you can see variable MY_MESSAGE does not exist in echo block.

1 Answer 1

2

You can put EOF in quotes: "EOF":

      UserData:
        !Base64 |
          #!/bin/bash
          cat <<"EOF" > /etc/aws-kinesis/start.sh
          #!/bin/sh
          MY_MESSAGE="Hello World"
          echo $MY_MESSAGE
          EOF
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.